我有以下代码:的Rails代码重构
@brand = Brand.find_by_id(params[:id])
if @brand.nil?
flash[:error] = Flash.record_not_found
redirect_to admin_brands_path
end
而另一变化如下:
@brand = Brand.find_by_id(params[:id])
return(flash[:error] = Flash.record_not_found and redirect_to admin_brands_path) if @brand.nil?
你认为哪个代码是更有效和解释? 当你有另一个建议,你也可以分享。
在此先感谢。
我的问题是:在Rails的MINITEST:我想测试一个控制器,让''从HTTP X Header' user_phone'参数值的方式。我怎样才能在'我的video_controller_test.rb'文件中发送这个参数。就像在我的'video_controller.rb'中得到的值为: 'user_phone = request.env ['HTTP_X_MSISDN'] .to_s' –