当我发布时,我可以在表单参数中看到authenticity_token,但我收到了这个错误消息:
Started POST "/helloasdf/destroy_task?id=29" for 127.0.0.1 at 2017-08-19 21:12:14 -0400
Processing by TaskController#destroy_task as JS
Parameters: {"authenticity_token"=>"XXXX", "id"=>"29", "task_url"=>"helloasdf"}
Can't verify CSRF token authenticity.
Completed 422 Unprocessable Entity in 1ms (ActiveRecord: 0.0ms)(我将内标识更改为XXXX)。
到底是什么问题,还是我做错了什么?
我的ApplicationController有:
class ApplicationController < ActionController::Base
protect_from_forgery with: :exception发布于 2017-08-20 09:30:08
这在不久前发生在我身上,我只是不明白为什么当我试图写一些东西的时候,它突然开始抛出这个错误。经过大约5个小时的调试后,我意识到我已经阻止了localhost:3000的cookies,一个大胆的猜测是,你可能也是这样。
发布于 2017-08-20 18:11:34
另一种猜测是,假设您使用application/x-www-form-urlencoded内容类型,您没有正确转义令牌-因为它是base64编码的,所以它可以包含加号(+),加号将被解释为空格,并且将无法通过真实性检查。
还要检查这个答案:Rails 3 Authenticity tokens: How to prevent it from using spaces? (尽管不管问题是什么,一个简单的令牌encodeURIComponent()也应该足够了)
https://stackoverflow.com/questions/45777630
复制相似问题