繁体   English   中英

在轨道上使用Sweetalert删除红宝石的方法

[英]Delete method with sweetalert in ruby on rails

嗨,我是使用Sweet Alert JS来使我的警报框更加精美的新手。 我正在使用普通的javascript警报确认来删除表中的特定数据。 但是,当我尝试在删除前运行甜蜜警报确认时,它将删除文件而不会弹出确认。

这是下面我的JS中的代码。

 $(".delete-alert").click(function(event) { event.preventDefault(); swal({ title: 'Are you sure?', text: "You won't be able to revert this!", type: 'warning', showCancelButton: true, confirmButtonColor: '#3085d6', cancelButtonColor: '#d33', confirmButtonText: 'Yes, delete it!' }).then(function () { swal( 'Deleted!', 'Your file has been deleted.', 'success' ) }); }); 

这是我的带有HTML的ruby,单击垃圾图标时调用上面的js

 <%= link_to raw('<i class="fa fa-trash delete-alert"></i>'), candidate_path(f.id),method: :delete %> 

这是如何使用Sweet Alert的完美示例。

            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) {
                    // Call your delete item function here.
                    swal("Deleted!", "Your imaginary file has been ted!", "success");
                } else {
                swal("Cancelled", "Your imaginary file is safe :)", "error");
                }
            });

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM