0

我在用户个人资料页面中定义了一个 link_to 来删除该帐户。

= link_to "Delete My Account", user_path(@user), :method=>:delete, :confirm => "Are you sure to delete your account?"

Jquery 代码位于 javascripts/application.js 中,如下所示:

var delete_path = $(this).attr('href');

$(".confirm").confirm({
text: "Are you sure you want to delete your account?",
title: "Confirmation required",

confirm: function(button) {
    alert("You have confirm!")
    window.location.href = delete_path;
},
cancel: function(button) {
     $(this).dialog("close");
},
confirmButton: "Yes I want to delete my account",
cancelButton: "No I want to go back",
post: true,
confirmButtonClass: "btn-danger",
cancelButtonClass: "btn-default",
dialogClass: "modal-dialog modal-lg" // Bootstrap classes for large modal});

实际上按钮功能很好,帐户已成功删除。但是确认对话框没有出现。我是 Jquery 的新手。不知道是不是漏掉了一些组件。

4

1 回答 1

0

我建议将您的删除链接从

= link_to "Delete My Account", user_path(@user), :method=>:delete, :confirm => "Are you sure to delete your account?"

= link_to "Delete My Account", user_path(@user), :method=>:delete, data: {:confirm => "Are you sure to delete your account?"}

删除记录前会显示确认对话框。

于 2015-11-06T04:40:56.433 回答