简体   繁体   English

在Ruby on Rails中的ActionController :: InvalidAuthenticityToken

[英]ActionController::InvalidAuthenticityToken in ruby on rails

I have a popup box name "Delete My account" where I am getting the password and delete account this password, below is the button where I click to open popup box: 我有一个弹出框名称“ Delete My account”,在其中我要获取密码并删除该密码帐户,下面是单击打开弹出框的按钮:

<table align="center" width="100%">
      <tr>
         <td>    
            <div class="btn_delmyaccount" align="center">
                <a id="DeleteMyAccount" class="buttonSearch">Delete My Account</a>
            </div>
         </td>
      </tr>
</table>

by using this javascript, open popup box: 通过使用此javascript,打开弹出框:

<script type="text/javascript">
                var e2=document.getElementById("DeleteMyAccount");
                e2.onclick = show_dialog3;
                function show_dialog3() {
                $( "#dialog2" ).dialog();
                }
</script>

And below is he popup form: 下面是他的弹出表单:

<div id="dialog2" title="Delete My Account" hidden="true">
                <%= form_tag({ controller: "settings", action: "delete_my_account"}, remote: "true" ) do |f| %>
                    <table style="text-align:center; vertical-align:top;">
                        <tr>
                            <td>
                                <div>
                                    <%= label_tag(:password, "Password") %>
                                    <%= password_field :tf_password, :placeholder => "Password" %>
                                </div>
                            </td>
                        </tr>
                    </table>
                    <table align="center" width="63%">
                        <tr>
                            <td style="text-align:right;">
                                <%= submit_tag 'Submit', :id => "_button1" %>
                            </td>
                        </tr>
                    </table>
                <% end %>
</div

And below is javascript for submitting the form: 以下是用于提交表单的javascript:

<script type="text/javascript">
$(document).ready(function() {
    // '_button' is the Id of your submit button
    $("#_button1").click(function() {            
      $(this).closest("form").submit();
      $("#dialog2").dialog("close");
    });
});
</script>

And problem is that when I click submit button on the popup box, I am getting an error below: 问题是,当我单击弹出框上的“提交”按钮时,出现以下错误:

ActionController::InvalidAuthenticityToken

To resolve this issue I add authenticity_token: "true" in form like below: 要解决此问题,我以如下形式添加authenticity_token: "true"

<%= form_tag({ controller: "settings", action: "delete_my_account" , authenticity_token: "true" }, remote: "true" ) do |f| %>
<% end %>

After that still I am getting another error below: 之后,我仍然在下面出现另一个错误:

ActionController::InvalidAuthenticityToken

Kindly suggest me, what should I do to resolve this issue, waiting for your reply. 请建议我,如何解决此问题,等待您的答复。 Thanks. 谢谢。

According to this question , the problem is typically with the CSRF tags in Rails 根据这个问题 ,问题通常是与Rails中的CSRF标签有关

They suggest including the csrf meta tags in your application layout. 他们建议在您的application布局中包含csrf元标记。 Do you have this: 你有这个吗:

#app/views/layouts/application.html.erb
<%= csrf_meta_tags %>

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

相关问题 Rails 4中的ActionController :: InvalidAuthenticityToken - ActionController::InvalidAuthenticityToken in rails 4 ActionController :: InvalidAuthenticityToken轨道5 - ActionController::InvalidAuthenticityToken rails 5 ActionController :: UnknownFormat(Ruby on Rails) - ActionController::UnknownFormat (Ruby on Rails) Ruby on Rails-AJAX问题(ActionController:UnknownFormat) - Ruby on Rails - Issues with AJAX (ActionController:UnknownFormat) webpack jquery ajax rails 5 InvalidAuthenticityToken - webpack jquery ajax rails 5 InvalidAuthenticityToken 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 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