0
我想用SweetAlert替換我的「確認」刪除。Rails Bootstrap確認刪除使用Sweetalert
目前正常工作以正常警報對話框刪除觀察者。我不知道如何調用sweetalert.js。
對不起,如果這是一個愚蠢的問題。我很新!謝謝!
team.html.erb
<td>
<div class="btn-group">
<%= link_to "/members/observers/#{observation.id}", class: "btn btn-xs btn-danger", method: :delete, data: { confirm: "Are you sure?" } do %>
<i class="fa fa-times fa-fw" data-toggle="tooltip" data-placement="top" title="Remove Observer"></i>
<% end %>
</div>
</td>
sweetalert.js
swal({
title: "Are you sure?",
text: "You will not be able to recover this imaginary file!",
type: "warning",
showCancelButton: true,
confirmButtonClass: "btn-danger",
confirmButtonText: "Yes, delete it!",
cancelButtonText: "No, cancel plx!",
closeOnConfirm: false,
closeOnCancel: false
},
function(isConfirm) {
if (isConfirm) {
swal("Deleted!", "Your imaginary file has been deleted.", "success");
} else {
swal("Cancelled", "Your imaginary file is safe :)", "error");
}
});
我忘了提及sweetalert寶石安裝,似乎工作正常。 – NU2Rails
更新。我現在通過向btn添加一個「sweet_delete」類來調用sweetalert.js。因此它會打開sweetalert提示符,但不管在警報中選擇什麼選項,它都會繼續執行刪除操作。 – NU2Rails