What is the easiest way to ask rails 3 "Are you sure you want to do this?" when does the user click on the link?
the link in this case overwrites some data with the new value. This is a simple link_to (GET) back to the same controller method, with the [] parameter added.
EDIT:<%= link_to "Do something", {:controller => "foo", :action => "bar"}, :confirm => "Are you sure you want to do that?" %>
<%= link_to "Do something", {:controller => "foo", :action => "bar"}, :confirm => "Are you sure you want to do that?" %>
For people like me who came here but are on Rails 4/5:
link_to "Title", some_path, data: { confirm: "Are you sure?" }
Documentation
There is an option :confirm :
:confirm
link_to "Visit Other Site", "http://www.rubyonrails.org/", :confirm => "Are you sure?" # => <a href="http://www.rubyonrails.org/" data-confirm="Are you sure?"">Visit Other Site</a>
You must have an unobtrusive JavaScript driver, such as this one for jQuery. It is pretty simple to set up.
Details are in the Rails API . You can read more about UJS in Rails 3 in this tutorial .