Rails-在删除之前自定义确认对话框的视图

时间:2017-10-23 06:48:37

标签: ruby-on-rails ruby ruby-on-rails-4

要删除rails中的记录,我正在使用此代码  <%= link_to"关闭#{user.name}' s",light_path(id:light),方法:: delete,data:{confirm:'你确定吗? ?' }%> 结果,我得到像enter image description here

这样的对话框

但是我希望这个对话框看起来像这样 enter image description here

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

1 个答案:

答案 0 :(得分:5)

您可以使用bootstrap模式对话框,如下所示:

<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>

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

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

我希望这对你有帮助。