【功能】controller中verify_authenticity_token上传到heroku出现bug

原本代码:

application_controller.rb
1
2
3
class < ActionController::Base
protect_from_forgery with: :exception
skip_before_action :verify_authenticity_token

本地运行app没有问题,上传到Heroku成功,打开Heroku app开始报错“Application Error”。输入heroku run rails console发现问题是verify_authenticity_token has not been defined (ArgumentError)

修改:

application_controller.rb
1
2
3
class < ActionController::Base
protect_from_forgery with: :exception

不确定为什么之前加了这一行,但改好之后整个app运行正常,原本设计在登陆前能看到的东西都可以看到,改要求登陆的地方也都会正常要求登陆。

参考:
http://stackoverflow.com/questions/39260198/verify-authenticity-token-has-not-been-defined

https://github.com/rails/rails/blob/master/actionpack/lib/action_controller/metal/request_forgery_protection.rb#L122