在application_controller.rb中:4
class ApplicationController < ActionController::Base
before_action :prepare_meta_tags, if: "request.get?"
Rails 5.1警告
DEPRECATION WARNING: Passing string to be evaluated in :if and :unless conditional options is deprecated and will be removed in Rails 5.2 without replacement. Pass a symbol for an instance method, or a lambda, proc or block, instead. (called from <class:ApplicationController> at MYSITE/app/controllers/application_controller.rb:4)
问题:
我有if,除非在我的项目中全部完成。需要建议。感谢
答案 0 :(得分:27)
首先,不要担心他们不会弃用:if和:除非。他们不赞成将字符串传递给它。
在这种情况下,使用lambda会更好
class ApplicationController < ActionController::Base
before_action :prepare_meta_tags, if: -> { request.get? }
...
end