views:

580

answers:

2

After returning to an old Rails project I found none of the destroy/delete links worked and clicking cancel on the confirmation popup would still submit the link.

Example of my code is:

<%= link_to 'Delete', admin_user_path(@user), :confirm => 'Are you sure?', :method => :delete %>
+1  A: 

Well it turns out that it was caused by the Firefox Firebug addon... Deleted the addon and everything works fine. Very annoying...

Chris Gaunt
What HTML/JavaScript does the rails statement produce? Maybe the error can be nailed down, under normal circumstances FireBug does not interfere so bluntly.
Tomalak
A: 

Chris, Hi. I had the same problem. I deleted Firebug and the problem persisted. I read from another user that he needed to restart Firefox, that didn't work either. Some said try Safari, that didn't work either.

In the end it was a novice thing:

I have helpers to insert an icon, like edit_icon, which return a nice image tag for the edit icon, etc.

One of these helper methods was the delete_icon method, where I wrote like this:

def delete_icon(object=nil) link_to image_tag('icons/delete.jpg', :width => 20, :border=>0), object, :confirm => 'Are you sure?', :method => :delete end

It was a (good) attempt at DRY, but better it would have been had I just had def delete_icon(object), and not object=nil, because it makes it clearer when I call it that I must pass it the object to destroy. Calling the same method with the object to be deleted worked for me.

In short: double check your helper methods if you're trying to DRY.

mjnissim