我在用户个人资料页面中定义了一个 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 的新手。不知道是不是漏掉了一些组件。