Rails- customize view of confirm dialog box before delete

偶尔善良 提交于 2021-01-03 22:56:44

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/46883416/rails-customize-view-of-confirm-dialog-box-before-delete

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!