我正在尝试更换我的"确认"使用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");
}
});
答案 0 :(得分:0)
确保 jquery
文件中包含jquery_ujs
和application.js
。
//= require jquery
//= require jquery_ujs
并安装'jquery-rails'
gem,如果你还没有。
gem 'jquery-rails'
然后运行bundle install
我相信你很高兴! :)