jquery - 这是什么意思 ? >> ActionController::InvalidAuthenticityToken

标签 jquery ruby-on-rails ruby

我很好奇这一般意味着什么。

但这里是细节..

我正在做一个可排序的 jquery 项目,涉及这个 rails Action :

def update_order
  params[:media].each_with_index do |id, index|
    media = @organization.media.find(id)
    media.do_not_touch = true
    media.update_attribute('position', index+1)
  end if params[:media]
  render :nothing => true
end

我只是在寻找出现此错误的一般原因。

最佳答案

rails automatically checks对于提交数据时的伪造数据。来自文档:

Protecting controller actions from CSRF attacks by ensuring that all forms are coming from the current web application, not a forged link from another site, is done by embedding a token based on a random string stored in the session (which an attacker wouldn‘t know) in all forms and Ajax requests generated by Rails and then verifying the authenticity of that token in the controller

您可以为给定的 Ajax 调用禁用此功能,或者您也可以发送一个名为“authenticity_token”且值为 <%= form_authenticity_token %> 的参数。

要禁用它(我不推荐这样做),您可以执行以下操作之一:

class FooController < ApplicationController
  protect_from_forgery :except => :update_order

  # you can disable csrf protection on controller-by-controller basis:
  skip_before_filter :verify_authenticity_token
end

关于jquery - 这是什么意思 ? >> ActionController::InvalidAuthenticityToken,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3558816/

相关文章:

jquery - ajax超时回调函数

ruby-on-rails - 如何克服 Excel CSV 编码噩梦 : "\xEF" from ASCII-8BIT to UTF-8"using Ruby on Rails

ruby-on-rails - Rails ActiveRecord 铲运算符 (<<) 更新未成功,日志中无异常

ruby-on-rails - 即使设置了错误,Rails Record 也会被保存

javascript - 仅在内容更新时自动刷新网页

javascript - 未捕获的引用错误 : Unexpected Token }

javascript - 如何从 url 获取访问 token

ruby-on-rails - 未显示部分渲染

ruby - 使用 RSpec 测试纯 Ruby bin/my_app.rb 应用程序?

ruby-on-rails - 不幸的是,发生了 fatal error 。请参阅 Bundler 故障排除文档