ifad / data-confirm-modal

Makes Rails' link_to confirm: 'foo' build a Bootstrap Modal instead of calling the browser's confirm() API.
MIT License
271 stars 115 forks source link

jquery-ujs non-GET requests not working #43

Closed vamsipavanmahesh closed 8 years ago

vamsipavanmahesh commented 8 years ago

The url went like this http://localhost:3000/cart/10fb416e-a97b-4cf6-9501-fd4417669b2b

<%= link_to cart_path(cart_item.id), method: :delete,class: 'remove-cart-item', data: {confirm: 'Are you sure that you want to remove from this cart'} do %>

//= require data-confirm-modal if i remove this line, everything works fine.

lucaspiller commented 8 years ago

The way this works with jquery-ujs is to hook into the confirm event, run our code, then afterwards hopefully reset to what was there originally - in your case Rails' trickery, to allow the delete action to be called:

https://github.com/ifad/data-confirm-modal/blob/master/vendor/assets/javascripts/data-confirm-modal.js#L287-L298

Check that you have jquery-ujs before data-confirm-modal in your application.js, otherwise yes it's a bug :D

lucaspiller commented 8 years ago

I just tested it, I have the following and it works correctly:

= link_to secrect_action_foo_path(@foo), method: :post, class: 'btn btn-default', data: { confirm: t('.secrect_action_confirm') } do
  = t('.secret_action')

Check the order of files in your application.js, it should be:

  1. jquery
  2. jquery-ujs
  3. bootstrap
  4. data-confirm-modal