I wanted to add confirmation message on link_to function with Ruby.
= link_to \'Reset message\', :action=>\'reset\' ,:confirm=>\'Are you sure?\'
<%= link_to 'Reset Message', data: {confirm:"Are you sure?"} %>
remember to add the path, between 'reset message' and data
Somehow does not work those code only Safari browser So I was involved button...
<%= button_to('', delete_path(), method: "delete", data: { confirm: 'Are you sure?', disable_with: 'loading...' }) %>
First, we need to understand what Js package respond to this kind of alerts in rails application. So for this, jquery_ujs package is reponsible for showing the alerts in rails.
So you must have jquery & jquery_ujs in your application.js file.
//= require jquery
//= require jquery_ujs
Now, we need to confirm, that application.js file is included in your required layout or not. By default layout file remains in application.html.erb in layout folder of views.
<%= javascript_include_tag 'application' %>
Next the link should have data-confirm & data-method attributes as
<a href="/message/1/reset" data-method="delete" data-confirm="Are you sure?">
In erb, this can be written as,
= link_to 'Reset', message_path(@message), data: {method: 'delete', confirm: 'Are you sure?'}
This should work if everything is aligned in same fashion.
watch this railscasts video for better understanding.
http://railscasts.com/episodes/205-unobtrusive-javascript
rails documentation for link_to helper.
http://api.rubyonrails.org/classes/ActionView/Helpers/UrlHelper.html#method-i-link_to