RubyVersion2.2.4,Rails版本5.0.0.1。
我被困在一个教程的一部分,在那里你用curl测试登录。我犯了个错误
ArgumentError (在process_action回调之前: verify_authenticity_token尚未定义)。
我在sessions_controller中使用了以下代码:
skip_before_action :verify_authenticity_token, :if => Proc.new { |c| c.request.format == 'application/json' }有人知道答案吗?
发布于 2016-09-05 08:09:48
检查ApplicationController是否调用了protect_from_forgery,如下所示:
class ApplicationController < ActionController::Base
protect_from_forgery with: :exception
end本质上,调用protect_from_forgery将verify_authenticity_token添加到before_filter列表中,您可以在其他控制器中跳过该列表。
有关更多信息,请参考文档。
发布于 2018-01-07 07:20:45
升级到Rails 5后,我碰到了这个错误。我发现,如果使用相同的方法名多次调用skip_before_action,则会引发此异常。
我的修正是将参数raise: false添加到第二次调用skip_before_filter。
因此,在应用程序控制器中应该是这样的:
skip_before_action :your_method_name, raise: false发布于 2019-02-21 21:31:40
升级到Rails 5并部署到Heroku之后,我遇到了这个错误。我无法在发展中复制它。
在API文档中给出了一个例子
class ApplicationController < ActionController::Base
protect_from_forgery unless: -> { request.format.json? }
end对我来说,添加像上面这样的unless: -> { request.format.json? }来修正我的堆叠炸弹。不幸的是,raise: false没有。
https://stackoverflow.com/questions/39260198
复制相似问题