- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
最近部署后,在 Heroku 上运行应用程序时,我遇到了解决以下错误的问题:
ActionController::InvalidAuthenticityToken
在以下情况下发生:登录/退出并提交表单,大约 75% 的时间会出现错误消息。
它与 csrf/真实性 token 有关,但是过去一切正常,并且在开发中没有问题。
<%= csrf_meta_tags %> 和authenticity_tokens 包含在表单中。
这怎么会突然发生?
Heroku 日志
2014-03-22T12:19:27.996333+00:00 app[web.2]: bin/rails:4:in `require'
2014-03-22T12:19:27.996335+00:00 app[web.2]: bin/rails:4:in `<main>'
2014-03-22T12:19:27.996354+00:00 app[web.2]: vendor/bundle/ruby/1.9.1/gems/actionpack-4.0.3/lib/abstract_controller/ca
llbacks.rb:17:in `process_action'
2014-03-22T12:19:27.996360+00:00 app[web.2]: vendor/bundle/ruby/1.9.1/gems/activesupport-4.0.3/lib/active_support/noti
fications/instrumenter.rb:20:in `instrument'
2014-03-22T12:19:27.996368+00:00 app[web.2]: vendor/bundle/ruby/1.9.1/gems/actionpack-4.0.3/lib/abstract_controller/ba
se.rb:136:in `process'
2014-03-22T12:19:27.996336+00:00 app[web.2]:
2014-03-22T12:19:27.996362+00:00 app[web.2]: vendor/bundle/ruby/1.9.1/gems/activesupport-4.0.3/lib/active_support/noti
fications.rb:159:in `instrument'
2014-03-22T12:19:27.996378+00:00 app[web.2]: vendor/bundle/ruby/1.9.1/gems/actionpack-4.0.3/lib/action_dispatch/routin
g/route_set.rb:80:in `call'
2014-03-22T12:19:27.996355+00:00 app[web.2]: vendor/bundle/ruby/1.9.1/gems/actionpack-4.0.3/lib/action_controller/meta
l/rescue.rb:29:in `process_action'
2014-03-22T12:19:27.996337+00:00 app[web.2]:
2014-03-22T12:19:27.996283+00:00 app[web.2]: vendor/bundle/ruby/1.9.1/gems/activesupport-4.0.3/lib/active_support/cach
e/strategy/local_cache.rb:83:in `call'
2014-03-22T12:19:27.996277+00:00 app[web.2]: vendor/bundle/ruby/1.9.1/gems/railties-4.0.3/lib/rails/rack/logger.rb:20:
in `call'
2014-03-22T12:19:27.996341+00:00 app[web.2]: vendor/bundle/ruby/1.9.1/gems/actionpack-4.0.3/lib/action_controller/meta
l/request_forgery_protection.
rb:163:in `handle_unverified_request'
2014-03-22T12:19:27.996239+00:00 app[web.2]: vendor/bundle/ruby/1.9.1/gems/rack-1.5.2/lib/rack/conditionalget.rb:35:in
`call'
2014-03-22T12:19:27.996275+00:00 app[web.2]: vendor/bundle/ruby/1.9.1/gems/activesupport-4.0.3/lib/active_support/tagg
ed_logging.rb:67:in `tagged'
2014-03-22T12:19:27.996363+00:00 app[web.2]: vendor/bundle/ruby/1.9.1/gems/actionpack-4.0.3/lib/action_controller/meta
l/instrumentation.rb:30:in `process_action'
2014-03-22T12:19:27.996399+00:00 app[web.2]: vendor/bundle/ruby/1.9.1/gems/actionpack-4.0.3/lib/action_dispatch/middle
ware/cookies.rb:486:in `call'
2014-03-22T12:19:27.996338+00:00 app[web.2]:
2014-03-22T12:19:27.996357+00:00 app[web.2]: vendor/bundle/ruby/1.9.1/gems/actionpack-4.0.3/lib/action_controller/meta
l/instrumentation.rb:31:in `block in process_action'
2014-03-22T12:19:27.996384+00:00 app[web.2]: vendor/bundle/ruby/1.9.1/gems/actionpack-4.0.3/lib/action_dispatch/journe
y/router.rb:59:in `call'
2014-03-22T12:19:27.996297+00:00 app[web.2]: vendor/bundle/ruby/1.9.1/gems/thin-1.6.2/lib/thin/connection.rb:84:in `pr
e_process'
2014-03-22T12:19:27.996344+00:00 app[web.2]: vendor/bundle/ruby/1.9.1/gems/actionpack-4.0.3/lib/action_controller/meta
l/request_forgery_protection.rb:170:in `handle_unverified_request'
2014-03-22T12:19:27.996251+00:00 app[web.2]: vendor/bundle/ruby/1.9.1/gems/activerecord-4.0.3/lib/active_record/query_
cache.rb:36:in `call'
2014-03-22T12:19:27.996280+00:00 app[web.2]: vendor/bundle/ruby/1.9.1/gems/rack-1.5.2/lib/rack/methodoverride.rb:21:in
`call'
2014-03-22T12:19:27.996387+00:00 app[web.2]: vendor/bundle/ruby/1.9.1/gems/rack-1.5.2/lib/rack/etag.rb:23:in `call'
2014-03-22T12:19:27.996340+00:00 app[web.2]: ActionController::InvalidAuthenticityToken (ActionController::InvalidAuthen
ticityToken):
2014-03-22T12:19:27.996365+00:00 app[web.2]: vendor/bundle/ruby/1.9.1/gems/actionpack-4.0.3/lib/action_controller/meta
l/params_wrapper.rb:245:in `process_action'
2014-03-22T12:19:27.996358+00:00 app[web.2]: vendor/bundle/ruby/1.9.1/gems/activesupport-4.0.3/lib/active_support/noti
fications.rb:159:in `block in instrument'
2014-03-22T12:19:27.996400+00:00 app[web.2]: vendor/bundle/ruby/1.9.1/gems/activerecord-4.0.3/lib/active_record/query_
cache.rb:36:in `call'
2014-03-22T12:19:27.996305+00:00 app[web.2]: vendor/bundle/ruby/1.9.1/gems/thin-1.6.2/lib/thin/backends/base.rb:73:in
`start'
2014-03-22T12:19:27.996294+00:00 app[web.2]: vendor/bundle/ruby/1.9.1/gems/thin-1.6.2/lib/thin/connection.rb:86:in `bl
ock in pre_process'
2014-03-22T12:19:27.996349+00:00 app[web.2]: vendor/bundle/ruby/1.9.1/gems/actionpack-4.0.3/lib/action_controller/meta
l/request_forgery_protection.rb:177:in `verify_authenticity_token'
2014-03-22T12:19:27.996268+00:00 app[web.2]: vendor/bundle/ruby/1.9.1/gems/actionpack-4.0.3/lib/action_dispatch/middle
ware/show_exceptions.rb:30:in `call'
2014-03-22T12:19:27.996292+00:00 app[web.2]: vendor/bundle/ruby/1.9.1/gems/rack-1.5.2/lib/rack/content_length.rb:14:in
`call'
2014-03-22T12:19:27.996403+00:00 app[web.2]: vendor/bundle/ruby/1.9.1/gems/actionpack-4.0.3/lib/action_dispatch/middle
ware/callbacks.rb:29:in `block in call'
2014-03-22T12:19:27.996410+00:00 app[web.2]: vendor/bundle/ruby/1.9.1/gems/actionpack-4.0.3/lib/action_dispatch/middle
ware/callbacks.rb:27:in `call'
2014-03-22T12:19:27.996411+00:00 app[web.2]: vendor/bundle/ruby/1.9.1/gems/actionpack-4.0.3/lib/action_dispatch/middle
ware/remote_ip.rb:76:in `call'
2014-03-22T12:19:27.996372+00:00 app[web.2]: vendor/bundle/ruby/1.9.1/gems/actionpack-4.0.3/lib/abstract_controller/re
ndering.rb:44:in `process'
2014-03-22T12:19:27.996376+00:00 app[web.2]: vendor/bundle/ruby/1.9.1/gems/actionpack-4.0.3/lib/action_controller/meta
l.rb:231:in `block in action'
2014-03-22T12:19:27.996418+00:00 app[web.2]: vendor/bundle/ruby/1.9.1/gems/activesupport-4.0.3/lib/active_support/tagg
ed_logging.rb:67:in `block in tagged'
2014-03-22T12:19:27.996422+00:00 app[web.2]: vendor/bundle/ruby/1.9.1/gems/railties-4.0.3/lib/rails/rack/logger.rb:20:
in `call'
2014-03-22T12:19:27.996391+00:00 app[web.2]: vendor/bundle/ruby/1.9.1/gems/actionpack-4.0.3/lib/action_dispatch/middle
ware/params_parser.rb:27:in `call'
2014-03-22T12:19:27.996402+00:00 app[web.2]: vendor/bundle/ruby/1.9.1/gems/activerecord-4.0.3/lib/active_record/connec
tion_adapters/abstract/connection_pool.rb:626:in `call'
2014-03-22T12:19:27.996423+00:00 app[web.2]: vendor/bundle/ruby/1.9.1/gems/actionpack-4.0.3/lib/action_dispatch/middle
ware/request_id.rb:21:in `call'
2014-03-22T12:19:27.996435+00:00 app[web.2]: vendor/bundle/ruby/1.9.1/gems/railties-4.0.3/lib/rails/application.rb:97:
in `call'
2014-03-22T12:19:27.996432+00:00 app[web.2]: vendor/bundle/ruby/1.9.1/gems/actionpack-4.0.3/lib/action_dispatch/middle
ware/ssl.rb:24:in `call'
2014-03-22T12:19:27.996437+00:00 app[web.2]: vendor/bundle/ruby/1.9.1/gems/rack-1.5.2/lib/rack/content_length.rb:14:in
`call'
2014-03-22T12:19:27.996394+00:00 app[web.2]: vendor/bundle/ruby/1.9.1/gems/rack-1.5.2/lib/rack/session/abstract/id.rb:
225:in `context'
2014-03-22T12:19:27.996412+00:00 app[web.2]: vendor/bundle/ruby/1.9.1/gems/actionpack-4.0.3/lib/action_dispatch/middle
ware/debug_exceptions.rb:17:in `call'
2014-03-22T12:19:27.996450+00:00 app[web.2]: vendor/bundle/ruby/1.9.1/gems/rack-1.5.2/lib/rack/handler/thin.rb:16:in `
run'
2014-03-22T12:19:27.996445+00:00 app[web.2]: vendor/bundle/ruby/1.9.1/gems/eventmachine-1.0.3/lib/eventmachine.rb:187:
in `run_machine'
2014-03-22T12:19:27.996446+00:00 app[web.2]: vendor/bundle/ruby/1.9.1/gems/eventmachine-1.0.3/lib/eventmachine.rb:187:
in `run'
2014-03-22T12:19:27.996397+00:00 app[web.2]: vendor/bundle/ruby/1.9.1/gems/rack-1.5.2/lib/rack/session/abstract/id.rb:
220:in `call'
2014-03-22T12:19:27.996449+00:00 app[web.2]: vendor/bundle/ruby/1.9.1/gems/thin-1.6.2/lib/thin/server.rb:162:in `start
'
2014-03-22T12:19:27.996453+00:00 app[web.2]: vendor/bundle/ruby/1.9.1/gems/railties-4.0.3/lib/rails/commands/server.rb
:84:in `start'
2014-03-22T12:19:27.996463+00:00 app[web.2]:
2014-03-22T12:19:27.996452+00:00 app[web.2]: vendor/bundle/ruby/1.9.1/gems/rack-1.5.2/lib/rack/server.rb:264:in `start
'
2014-03-22T12:19:27.996414+00:00 app[web.2]: vendor/bundle/ruby/1.9.1/gems/actionpack-4.0.3/lib/action_dispatch/middle
ware/show_exceptions.rb:30:in `call'
2014-03-22T12:19:27.996274+00:00 app[web.2]: vendor/bundle/ruby/1.9.1/gems/activesupport-4.0.3/lib/active_support/tagg
ed_logging.rb:25:in `tagged'
2014-03-22T12:19:27.996459+00:00 app[web.2]: bin/rails:4:in `require'
2014-03-22T12:19:27.996457+00:00 app[web.2]: vendor/bundle/ruby/1.9.1/gems/railties-4.0.3/lib/rails/commands.rb:71:in
`<top (required)>'
2014-03-22T12:19:27.996425+00:00 app[web.2]: vendor/bundle/ruby/1.9.1/gems/rack-1.5.2/lib/rack/methodoverride.rb:21:in
`call'
2014-03-22T12:19:27.996303+00:00 app[web.2]: vendor/bundle/ruby/1.9.1/gems/eventmachine-1.0.3/lib/eventmachine.rb:187:
in `run'
2014-03-22T12:19:27.996366+00:00 app[web.2]: vendor/bundle/ruby/1.9.1/gems/activerecord-4.0.3/lib/active_record/railti
es/controller_runtime.rb:18:in `process_action'
2014-03-22T12:19:27.996375+00:00 app[web.2]: vendor/bundle/ruby/1.9.1/gems/actionpack-4.0.3/lib/action_controller/meta
l/rack_delegation.rb:13:in `dispatch'
2014-03-22T12:19:27.996351+00:00 app[web.2]: vendor/bundle/ruby/1.9.1/gems/activesupport-4.0.3/lib/active_support/call
backs.rb:377:in `_run__3606036784356827589__process_action__callbacks'
2014-03-22T12:19:27.996448+00:00 app[web.2]: vendor/bundle/ruby/1.9.1/gems/thin-1.6.2/lib/thin/backends/base.rb:73:in
`start'
2014-03-22T12:19:27.996290+00:00 app[web.2]: vendor/bundle/ruby/1.9.1/gems/railties-4.0.3/lib/rails/application.rb:97:
in `call'
2014-03-22T12:19:27.996307+00:00 app[web.2]: vendor/bundle/ruby/1.9.1/gems/thin-1.6.2/lib/thin/server.rb:162:in `start
'
2014-03-22T12:19:27.996373+00:00 app[web.2]: vendor/bundle/ruby/1.9.1/gems/actionpack-4.0.3/lib/action_controller/meta
l.rb:195:in `dispatch'
2014-03-22T12:19:27.996382+00:00 app[web.2]: vendor/bundle/ruby/1.9.1/gems/actionpack-4.0.3/lib/action_dispatch/journe
y/router.rb:71:in `block in call'
2014-03-22T12:19:27.996352+00:00 app[web.2]: vendor/bundle/ruby/1.9.1/gems/activesupport-4.0.3/lib/active_support/call
backs.rb:80:in `run_callbacks'
2014-03-22T12:19:27.996302+00:00 app[web.2]: vendor/bundle/ruby/1.9.1/gems/eventmachine-1.0.3/lib/eventmachine.rb:187:
in `run_machine'
2014-03-22T12:19:27.996308+00:00 app[web.2]: vendor/bundle/ruby/1.9.1/gems/rack-1.5.2/lib/rack/handler/thin.rb:16:in `
run'
2014-03-22T12:19:27.996404+00:00 app[web.2]: vendor/bundle/ruby/1.9.1/gems/activesupport-4.0.3/lib/active_support/call
backs.rb:373:in `_run__2997722282201691042__call__callbacks'
2014-03-22T12:19:27.996419+00:00 app[web.2]: vendor/bundle/ruby/1.9.1/gems/activesupport-4.0.3/lib/active_support/tagg
ed_logging.rb:25:in `tagged'
2014-03-22T12:19:27.996381+00:00 app[web.2]: vendor/bundle/ruby/1.9.1/gems/actionpack-4.0.3/lib/action_dispatch/routin
g/route_set.rb:48:in `call'
2014-03-22T12:19:27.996386+00:00 app[web.2]: vendor/bundle/ruby/1.9.1/gems/actionpack-4.0.3/lib/action_dispatch/routin
g/route_set.rb:680:in `call'
2014-03-22T12:19:27.996434+00:00 app[web.2]: vendor/bundle/ruby/1.9.1/gems/railties-4.0.3/lib/rails/engine.rb:511:in `
call'
2014-03-22T12:19:27.996444+00:00 app[web.2]: vendor/bundle/ruby/1.9.1/gems/thin-1.6.2/lib/thin/connection.rb:39:in `re
ceive_data'
2014-03-22T12:19:27.996379+00:00 app[web.2]: vendor/bundle/ruby/1.9.1/gems/actionpack-4.0.3/lib/action_dispatch/routin
g/route_set.rb:80:in `dispatch'
2014-03-22T12:19:27.996405+00:00 app[web.2]: vendor/bundle/ruby/1.9.1/gems/activesupport-4.0.3/lib/active_support/call
backs.rb:80:in `run_callbacks'
2014-03-22T12:19:27.996383+00:00 app[web.2]: vendor/bundle/ruby/1.9.1/gems/actionpack-4.0.3/lib/action_dispatch/journe
y/router.rb:59:in `each'
2014-03-22T12:19:27.996388+00:00 app[web.2]: vendor/bundle/ruby/1.9.1/gems/rack-1.5.2/lib/rack/conditionalget.rb:35:in
`call'
2014-03-22T12:19:27.996390+00:00 app[web.2]: vendor/bundle/ruby/1.9.1/gems/rack-1.5.2/lib/rack/head.rb:11:in `call'
2014-03-22T12:19:27.996462+00:00 app[web.2]:
2014-03-22T12:19:27.996421+00:00 app[web.2]: vendor/bundle/ruby/1.9.1/gems/activesupport-4.0.3/lib/active_support/tagg
ed_logging.rb:67:in `tagged'
2014-03-22T12:19:27.996415+00:00 app[web.2]: vendor/bundle/ruby/1.9.1/gems/railties-4.0.3/lib/rails/rack/logger.rb:38:
in `call_app'
2014-03-22T12:19:27.996417+00:00 app[web.2]: vendor/bundle/ruby/1.9.1/gems/railties-4.0.3/lib/rails/rack/logger.rb:20:
in `block in call'
2014-03-22T12:19:27.996393+00:00 app[web.2]: vendor/bundle/ruby/1.9.1/gems/actionpack-4.0.3/lib/action_dispatch/middle
ware/flash.rb:241:in `call'
2014-03-22T12:19:27.996429+00:00 app[web.2]: vendor/bundle/ruby/1.9.1/gems/actionpack-4.0.3/lib/action_dispatch/middle
ware/static.rb:64:in `call'
2014-03-22T12:19:27.996431+00:00 app[web.2]: vendor/bundle/ruby/1.9.1/gems/rack-1.5.2/lib/rack/sendfile.rb:112:in `cal
l'
2014-03-22T12:19:27.996442+00:00 app[web.2]: vendor/bundle/ruby/1.9.1/gems/thin-1.6.2/lib/thin/connection.rb:53:in `pr
ocess'
2014-03-22T12:19:27.996427+00:00 app[web.2]: vendor/bundle/ruby/1.9.1/gems/rack-1.5.2/lib/rack/runtime.rb:17:in `call'
2014-03-22T12:19:27.996438+00:00 app[web.2]: vendor/bundle/ruby/1.9.1/gems/thin-1.6.2/lib/thin/connection.rb:86:in `bl
ock in pre_process'
2014-03-22T12:19:27.996454+00:00 app[web.2]: vendor/bundle/ruby/1.9.1/gems/railties-4.0.3/lib/rails/commands.rb:76:in
`block in <top (required)>'
2014-03-22T12:19:27.996428+00:00 app[web.2]: vendor/bundle/ruby/1.9.1/gems/activesupport-4.0.3/lib/active_support/cach
e/strategy/local_cache.rb:83:in `call'
2014-03-22T12:19:27.996439+00:00 app[web.2]: vendor/bundle/ruby/1.9.1/gems/thin-1.6.2/lib/thin/connection.rb:84:in `ca
tch'
2014-03-22T12:19:27.996456+00:00 app[web.2]: vendor/bundle/ruby/1.9.1/gems/railties-4.0.3/lib/rails/commands.rb:71:in
`tap'
2014-03-22T12:19:27.996441+00:00 app[web.2]: vendor/bundle/ruby/1.9.1/gems/thin-1.6.2/lib/thin/connection.rb:84:in `pr
e_process'
2014-03-22T12:19:27.996460+00:00 app[web.2]: bin/rails:4:in `<main>'
最佳答案
如果没有更多信息,很难确切知道,但这是我的猜测:检查您的缓存实现。
如果抛出错误的页面是正在缓存的页面,并且您的真实性 token 已更改,则它们可能具有为提交表单等缓存的旧真实性 token ,这显然与较新的 token 不匹配。
这将解释为什么它在本地运行良好(您可能没有缓存),以及为什么它不会每次都失败(如果不是每个页面都被缓存)。
(哦,还有不相关的评论 - 请更新您的 rails 版本。4.0.3 中有一些重要的安全修复程序)
关于ruby-on-rails - Rails ActionController::InvalidAuthenticityToken 错误 Heroku,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22561733/
我在玩 cucumber 时发现我的 Rspec 测试开始失败。在我安装 cucumber 之前一切都运行良好。有任何想法吗? 日志 /Users/szymonborucki/.rbenv/versi
我知道这已经被提出 a few times在SO上,但我无法取得进展。我在 Rails 5.0.7.2 上。 我收到 ActionController::InvalidCrossOriginReque
以下是由我的 Rails 应用程序中的表单引起的错误: Processing UsersController#update (for **ip** at 2010-07-29 10:52:27) [P
我有这个遗留的 Spree 应用程序,带有 2 个带有继承回调的装饰 Controller : Spree::Api::BaseController.class_eval do before_ac
我很好奇这一般意味着什么。 但这里是细节.. 我正在做一个可排序的 jquery 项目,涉及这个 rails Action : def update_order params[:media].ea
我收到来自 "button" %> 线路的无路由匹配错误. 在我添加 gem 之前,这曾经有效,但现在它停止工作了。我尝试过收藏,但我没有运气,因为那是以前的地方。 路线: resources :
我发现使用诸如 foo.bar.uk.com 之类的域会导致 Rails扔一个 ActionController::InvalidAuthenticityToken提交任何表格时。 foo.bar.c
我有一个使用 ActionController::Metal on Rails 4.1.6 的 Api Controller ,如下所示: class Api < ActionController::
在我的 ActionController::Live 监听大约 5 分钟后,我在浏览器中看到以下内容,并且我的 EventSource 断开了连接。 EventSource 的响应具有不是“text/
我正在使用 Rail4 并尝试通过 GET 请求发送一些纯文本: def get_text respond_to do |format| format.text { render :tex
我的道路有问题,我不明白他为什么告诉我“Dashboard::TasksController”因为在我的 Controller 文件中包含文件 dashbaord/tasks.rb class Tas
我的 Controller 页面有问题。顺便说一句,我想执行 localhost:3000/article/donat?author_id=4,这意味着我只想查看 author_id = 4 的文章我
我正在运行一个 rails 应用程序,我有一个简单的显示操作,其中的代码类似于以下内容: @post = Post.find(params[:id]) 所以如果你去帖子/1 例如,如果有帖子,您将看到
在 Rails 4.1.6 中,我收到 InvalidAuthenticityToken运行使用脚手架生成的测试时出错。有没有办法禁用特定测试的真实性 token 检查? rails g scaffo
我正在努力使 ActionController::UnknownFormat不会在生产中引发异常报告。我正在使用 Rails 4 并认为这样的事情可以解决问题,但似乎没有什么区别: applicati
我正在尝试使用 Rails 4 的实时流实现文本/事件流。它工作得很好,我遇到的唯一麻烦是我无法在不发送任何消息的情况下检查连接是否有效。 我想出的唯一解决方案是使用循环滴答发生器制作支持 chann
我已经阅读了所有可以找到的类似问题,但仍然无法弄清我的问题。 # routes.rb Rails.application.routes.draw do resources :lists, only
我在 application_contoller.rb 中有一个方法,其中包含对 send_file 的调用。我从 javascript 渲染的部分调用它,并收到以下错误 - ActionView::
所以...第一次向 StackOverflow 提问... 我按照 Rails Guides 和 RailsApps 项目将现有的 Rails 4.2.5 应用程序(使用 Ruby 2.2.4)转换为
我有一个关于 Rails ActionController::Live 的问题 最后我想向用户展示 FFMPEG 的进展,但现在我想让这个最小的示例运行: Rails media_controller
我是一名优秀的程序员,十分优秀!