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