How to use: confirm with the button_to and: method: put buttons?

I have some destructive action that needs to be performed, so I believe that this is a Rails way to put such actions in PUT or POST (therefore link_to does not work, because it is only GET).

I added a button like this:

<%= button_to "Acknowledge", ack_something_path, :method => :put, :confirm => "Sure?" %> 

The button works (triggers the correct action), but I can't get Rails to display a confirm dialog.

Any ideas how to do this?

UPDATE (SOLVING THE PROBLEM)

I did not mention that I included jquery as well as the prototype in HEAD (I didn’t think it mattered). BUT, when I removed jquery, a confirmation dialog appeared.

I don’t know why this is happening, but the problem is solved (so far, one way or another). jquery and prototype do not like to work together, it seems.

+2
ruby-on-rails-3
source share
1 answer

I can show a confirmation dialog when copying code to my view.

Have you included the correct javascript file in the <head> section? The js file in public/javascripts/rails.js needed to include all js effects in auxiliary methods of the form.

You can check if <%= javascript_include_tag :defaults %> in head or not.

+2
source share

All Articles