The blog uses coffeescript. Suppose you use the :confirm parameter in the form of rails, then you need to override the default action in Rails by placing the following code in the <controller>.js.coffee in the pipeline of your assets ( app/assets/javascript ):
$.rails.allowAction = (link) -> return true unless link.attr('data-confirm') $.rails.showConfirmDialog(link) # look bellow for implementations false # always stops the action since code runs asynchronously $.rails.confirmed = (link) -> link.removeAttr('data-confirm') link.trigger('click.rails') $.rails.showConfirmDialog = (link) -> message = link.attr 'data-confirm' html = """ <div class="modal" id="confirmationDialog"> <div class="modal-header"> <a class="close" data-dismiss="modal">×</a> <h3>#{message}</h3> </div> <div class="modal-body"> <p>Are you sure you want to delete?</p> </div> <div class="modal-footer"> <a data-dismiss="modal" class="btn">Cancel</a> <a data-dismiss="modal" class="btn btn-primary confirm">OK</a> </div> </div> """ $(html).modal() $('#confirmationDialog .confirm').on 'click', -> $.rails.confirmed(link)
Then you can use such links in your view, and they should display the Bootstrap modem instead of the standard browser popup:
<%= link_to 'Delete', item, :method => :delete, :confirm=>'Are you sure?' %>
UPDATE
This works for me using the option :remote => true .
So, if there is something like the following in my view of index.html.erb:
<table> <tr> <th>Name</th> <th>Title</th> <th>Content</th> <th></th> <th></th> <th></th> </tr> <% @posts.each do |post| %> <tr id="<%= post.id %>"> <td><%= post.name %></td> <td><%= post.title %></td> <td><%= post.content %></td> <td><%= link_to 'Show', post %></td> <td><%= link_to 'Edit', edit_post_path(post) %></td> <td><%= link_to 'Destroy', post, method: :delete, :remote => true, data: { confirm: 'Are you sure?' } %></td> </tr> <% end %> </table>
And the destroy action in the controller has format.js in response_to:
And this is in the destroy.js.erb file:
$("tr#<%= @post.id %>").fadeOut();
Then everything works. When you click on the Destroy link, a download confirmation dialog box appears, and when you click OK, the line disappears and is destroyed on the server.