举个例子,如果我创建了一个普通的Rails3应用程序,并创建了一个单一的模型Task和单一字段Name。然后转到localhost:3000/tasks/new,检查页面,并将authenticity_token更改为"test“我可以提交表单。如果我在Rails 5应用程序中执行相同的用例,我会得到异常:
ActionController::InvalidAuthenticityToken in TasksController#create
ActionController::InvalidAuthenticityToken
Extracted source (around line
在我的rails博客应用程序中,当我尝试提交新帖子的表单时,收到以下错误消息:
PostsController#create ActionController::InvalidAuthenticityToken中的ActionController::InvalidAuthenticityToken提取的源文件(在第211行附近):
def handle_unverified_request
raise ActionController::InvalidAuthenticityToken
end
end
end
这是我的posts_contro
我正在为一个博客完成Ruby Rails教程,当我尝试提交一篇新文章时,浏览器会出现ActionController::InvalidAuthenticityToken错误。
我是Ruby Rails的新手(这就是我为什么要做这个教程的原因),我已经看过了示例,看过了各种各样的其他答案,但我似乎找不到问题所在?作为学习的一部分,我想了解这个问题以及如何解决它。
这是在提取的源代码中显示的内容: def handle_unverified_request raise ActionController::InvalidAuthenticityToken end end end
这来自服务器:参数:
嘿,我现在使用的是rails内置的最小的框架。尝试在我的ApplicationController中围绕protect_from_forgery测试一些方法,并从InvalidAuthenticityToken异常中恢复。作为参考,我的ApplicationController如下所示:
class ApplicationController < ActionController::Base
# Prevent CSRF attacks by raising an exception.
# For APIs, you may want to use :nul
我已经在本地删除了我的Rails GitHub项目,并重新克隆了它,但从那时起,当我试图通过Devise登录时,我得到了错误的"ActionController::InvalidAuthenticityToken“。
def handle_unverified_request
raise ActionController::InvalidAuthenticityToken
end
end
end
这对任何人来说都很熟悉吗?也许某种加密密钥已经被更改了?
我尝试了不同的浏览器,删除了我的cookies,但同样的问题。
谢谢
我创建了一个全新的rails-api应用程序,添加了一个地址模型,然后安装了rails_admin。并且每当我尝试添加行时,都会得到422的
我可以看到CSRF令牌已经在JSON中发送,但它显示无效。
Processing by RailsAdmin::MainController#new as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"9PP0EREx/cTK2TVtMp38ao/U9QCu6pjwmvV4fxIGEwTjZvGUfTcz7hpWL85
当CSRF令牌不匹配时,Rails将引发InvalidAuthenticityToken。但是,通过阅读,我无法弄清楚这实际上是如何发生的。我从这个类的树开始:
$ ack --ignore-dir=test InvalidAuthenticityToken
actionpack/lib/action_controller/metal/request_forgery_protection.rb
4: class InvalidAuthenticityToken < ActionControllerError #:nodoc:
17: # which will check the t
我正在构建一个运行在rails服务器上的Android应用程序。一开始,当我试图向服务器发布简单的字符串数据时,我遇到了一个InvalidAuthenticityToken问题,但是我意识到我可以通过将内容类型设置为"json“来绕过身份验证。
HttpClient client = new DefaultHttpClient();
HttpPost post = new HttpPost(Constants.REST_HOST + "/add_comment");
post.addHeader("Content-Type", "applicat
我正在为我的移动应用程序开发一些API,在一些POST操作中我得到了以下错误:
ActionController::InvalidAuthenticityToken
我的ActionController代码:
class ApplicationController < ActionController::Base
# Prevent CSRF attacks by raising an exception.
# For APIs, you may want to use :null_session instead.
protect_from_forgery with: :ex
所以,在我尝试在我的rails应用程序中实现AJAX注释后,我开始收到这个错误:
ActionController::InvalidAuthenticityToken in CommentsController#create
ActionController::InvalidAuthenticityToken
def handle_unverified_request
raise ActionController::InvalidAuthenticityToken
end
end
end
以下是相关文件中的所有代码:
comments_control
在我制作的一个应用程序中,我收到了很多这样的消息:
A ActionController::InvalidAuthenticityToken occurred in items#vote_up:
ActionController::InvalidAuthenticityToken
/var/lib/gems/1.8/gems/actionpack-2.3.4/lib/action_controller/request_forgery_protection.rb:79:in `verify_authenticity_token'
我怀疑这是因为人们在该页面上花费了大量时间而没有刷