2015-11-05 189 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?"} 

它會顯示確認對話框,刪除記錄之前。