[英]ActionController::InvalidAuthenticityToken rails 5
I'm using rails version - 5.0.0.1
我正在使用Rails版本
5.0.0.1
I used form_for
to create a form 我用
form_for
创建一个表单
<%= form_for :session,:action => '/login/authenicate/',:remote => true, :authenticity_token => true, :html => { :class => 'validate', :id => 'form_login' } do |s| %>
I am using ajax to send the request to the server. 我正在使用ajax将请求发送到服务器。
This is the form that is displayed in the browser. 这是浏览器中显示的表单。
<form class="validate" id="form_login" action="/login" accept-charset="UTF-8" data-remote="true" method="post" novalidate="novalidate"><input name="utf8" type="hidden" value="✓"><input type="hidden" name="authenticity_token" value="i3GVfaN2PbZ80JvdSqO921GuNLaxxo9ctsTBE21aYJYo/XtBG7lyqU7xAzoFjClwOGWSCrC+6mf3no39ua+rDQ==">
<div class="form-group">
<div class="input-group">
<div class="input-group-addon">
<i class="fa fa-user" aria-hidden="true"></i>
</div>
<input class="form-control" id="username" placeholder="Email Id / Mobile No" type="text" name="session[username]">
</div>
</div>
<div class="form-group">
<div class="input-group">
<div class="input-group-addon">
<i class="fa fa-lock" aria-hidden="true"></i>
</div>
<input class="form-control" id="password" placeholder="Passowrd" type="password" name="session[password]">
</div>
</div>
<div class="form-group">
<button name="authenicatebtn" type="submit" class="btn btn-primary btn-block btn-login">Login</button>
</div>
It is a ajax request to the server when i view in the networks tab its showing ActionController::InvalidAuthenticityToken
error. 当我在“网络”选项卡中查看其显示的
ActionController::InvalidAuthenticityToken
错误时,这是对服务器的Ajax请求。
From the Rails doc: 从Rails文档中:
:authenticity_token - Authenticity token to use in the form.
:authenticity_token-在表单中使用的真实性令牌。 Use only if you need to pass custom authenticity token string, or to not add authenticity_token field at all (by passing false).
仅在需要传递自定义真实性令牌字符串或根本不添加authenticity_token字段(通过传递false)时使用。
... Remote forms get the authenticity token from the meta tag, so embedding is unnecessary unless you support browsers without JavaScript.
...远程表单从meta标记获取真实性令牌,因此除非您支持不带JavaScript的浏览器,否则不需要嵌入。
What are you trying to achieve by passing :authenticity_token => true
in your form? 您要通过在表单中传递
:authenticity_token => true
来实现什么?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.