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