Rails-自定义删除前确认对话框的视图 [英] Rails- customize view of confirm dialog box before delete

查看:56
本文介绍了Rails-自定义删除前确认对话框的视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

要删除 rails 中的记录,我正在使用此代码

<%= link_to "close #{user.name}'s light", light_path(id: light), method: :delete, data: { confirm: 'Are you sure?'}%>

结果,我得到这样的对话框

但我希望这个对话框看起来像这样

有没有办法自定义确认对话框的默认视图?

解决方案

你可以使用 bootstrap modal dialog box,像这样:

并将您的初始链接更改为:

<%= link_to "close #{user.name}'s light", "javascript:void(0)", 'data-target': "#myModal", 'data-toggle':模态"%>

希望对你有帮助.

To delete a record in rails I am using this code

<%= link_to "close #{user.name}'s light", light_path(id: light), method: :delete, data: { confirm: 'Are you sure?' } %>

result of which, I get dialog box like this

But I wants this dialog box to look like this

Is there any way to customize the default view of confirm dialog box?

解决方案

You can make use of bootstrap modal dialog box, like this:

<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
    <h4

 class="modal-title" id="myModalLabel">Delete Confirmation</h4>
      </div>
      <div class="modal-body">
        Are you sure about closing Ellen's lightbox..
        <%= link_to "Yes", light_path(id: light), method: :delete %>/
        <%= link_to "No", "javascript:void(0)",'data-dismiss': "modal" %>
      </div>
    </div>
  </div>
</div>

And change your initial link to:

<%= link_to "close #{user.name}'s light", "javascript:void(0)", 'data-target': "#myModal", 'data-toggle': "modal" %>

I hope this might be helpful to you.

这篇关于Rails-自定义删除前确认对话框的视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
其他开发最新文章
热门教程
热门工具
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆