我得到了这个错误:ActionController::InvalidAuthenticityToken在我的webapp上的每一个帖子请求上。
我的临时解决方案是将它添加到控制器中:skip_before_action :verify_authenticity_token,但是当然,它会创建一个漏洞.
有谁知道为什么我会收到这个错误,这样我就可以在不创建漏洞的情况下修复它吗?
谢谢。
发布于 2015-08-29 11:47:44
您需要通过对控制器的HTTP调用发送身份验证令牌。通常,如果您使用的是form_for助手,那么您不需要显式地发送真实性令牌。但是,如果使用HTML <form>或Ajax请求,则必须在调用时发送此令牌。
Ajax
$.ajax({
.....,
beforeSend: function(xhr) {xhr.setRequestHeader('X-CSRF-Token', $('meta[name="csrf-token"]').attr('content'))},
....... });表单将此放在html表单标记中。
<%= tag(:input, :type => "hidden", :name => request_forgery_protection_token.to_s, :value => form_authenticity_token) %> https://stackoverflow.com/questions/32280916
复制相似问题