I've been searching for a while for a solution, but haven't been able to find out what is wrong with my code.
I'm trying to delete an item using an ajax call on an event page, but it doesn't seem to work.
<%= link_to 'X', { :controller => 'items', :action => 'destroy', :id => item.id }, :method => :delete, :confirm => 'Are you sure you want to delete this item?', :remote => true %>
<a rel="nofollow" data-method="delete" data-confirm="Are you sure you want to delete this item?" href="/items/83">X</a>
I believe everything looks right, however, the data attributes don't seem to work. No confirmation occurs when I click this and instead it calls the 'show' action for the controller, so the data-method is not working either.
The weirdest part is that I something else on the page that generates the confirmation messages.
<%= link_to image_tag("trashcan.png"), @event, :confirm => 'Are you sure you want to delete this event?', :method => :delete %>
<a rel="nofollow" data-method="delete" data-confirm="Are you sure you want to delete this event?" href="/events/3">
I've tried changing the 'X' in the first one to an image (in case an image_tag did the trick开发者_如何学C) - no luck. However, when I changed the link_to to a button_to it did delete, but not confirmation which I assume button does not support. So I'm not sure if I maybe has some javascript error somewhere else, which I assume to not be the case since it works in the other case or maybe I'm missing something somewhere.
Edit: I forgot to mention I also have a comment for each item and that works as well...
<%= link_to 'X', [comment.item, comment], :confirm => 'Are you sure?', :method => :delete, :remote => true %>
<a rel="nofollow" data-remote="true" data-method="delete" data-confirm="Are you sure?" href="/items/83/comments/32">X</a>
Fixed it, the problem was I had a div behind these links where I bound an click event to and in which I also called event.stopPropagation() thus prevented the data calls to be made.
精彩评论