简体   繁体   English

ActionController :: InvalidAuthenticityToken轨道5

[英]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.

相关问题 在Ruby on Rails中的ActionController :: InvalidAuthenticityToken - ActionController::InvalidAuthenticityToken in ruby on rails Rails 4中的ActionController :: InvalidAuthenticityToken - ActionController::InvalidAuthenticityToken in rails 4 webpack jquery ajax rails 5 InvalidAuthenticityToken - webpack jquery ajax rails 5 InvalidAuthenticityToken ActionController :: UnknownFormat(Ruby on Rails) - ActionController::UnknownFormat (Ruby on Rails) Rails 4,通过ajax提交表单,并通过回形针上传图像给出错误:InvalidAuthenticityToken - Rails 4, submitting a form by ajax and uploading an image by paperclip gives error: InvalidAuthenticityToken Rails 6.0.1 中 Ajax 请求的 ActionController::UnknownFormat 错误 - ActionController::UnknownFormat error with Ajax request in Rails 6.0.1 Ruby on Rails-AJAX问题(ActionController:UnknownFormat) - Ruby on Rails - Issues with AJAX (ActionController:UnknownFormat) Rails CORS:ActionController::RoutingError(没有路由匹配 [OPTIONS] &quot;/batches&quot;): - Rails CORS: ActionController::RoutingError (No route matches [OPTIONS] "/batches"): ActionController :: RoutingError(没有路由匹配“/javascripts/rails.js”) - ActionController::RoutingError (No route matches “/javascripts/rails.js”) Rails -TypeError:无法将ActionController :: Parameters转换为文本 - Rails -TypeError: can't cast ActionController::Parameters to text
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM