繁体   English   中英

ActionController :: InvalidAuthenticityToken轨道5

[英]ActionController::InvalidAuthenticityToken rails 5

我正在使用Rails版本5.0.0.1

我用form_for创建一个表单

<%= form_for :session,:action => '/login/authenicate/',:remote => true, :authenticity_token => true, :html => { :class => 'validate', :id => 'form_login' } do |s| %>

我正在使用ajax将请求发送到服务器。

这是浏览器中显示的表单。

<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>

当我在“网络”选项卡中查看其显示的ActionController::InvalidAuthenticityToken错误时,这是​​对服务器的Ajax请求。

从Rails文档中:

:authenticity_token-在表单中使用的真实性令牌。 仅在需要传递自定义真实性令牌字符串或根本不添加authenticity_token字段(通过传递false)时使用。

...远程表单从meta标记获取真实性令牌,因此除非您支持不带JavaScript的浏览器,否则不需要嵌入。

您要通过在表单中​​传递:authenticity_token => true来实现什么?

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM