2015-11-05 120 views
0

我在用户配置文件页面中定义了一个link_to以删除该帐户。删除确认对话框不显示

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

jQuery代码是Java脚本/ 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的新手。不知道是否遗漏了一些组件。

回答

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?"} 

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