I wanted to add confirmation message on link_to function with Ruby.
= link_to 'Reset message', :action=>'reset' ,:confirm=>'Are you sure?'
Any ideas why it's not working?
I wanted to add confirmation message on link_to function with Ruby.
= link_to 'Reset message', :action=>'reset' ,:confirm=>'Are you sure?'
Any ideas why it's not working?
Try this:
or to be more clear
Refer http://api.rubyonrails.org/classes/ActionView/Helpers/UrlHelper.html#method-i-link_to
You will see that there are 3 parameters, when you are giving url as options like
{:action => ..., :controller => ...}
In ruby, if the last parameter in a function call is a hash, you need not wrap it in
{}
characters (in other words, you can omit that in case, if the hash is the last parameter), so the code you have provided will be interpreted as a function call with only 2 parameters,'Reset message'
string and{:action=>'reset', :confirm=>'Are you sure?'}
hash and the:confirm=>'Are you sure?'
will be interpreted as aurl_option
instead of ahtml_option
Somehow does not work those code only Safari browser So I was involved button...
Look at your javascript_include_tag and it should work fine:
I might be mistaken but you don't specify a controller along with the
:action
option. Have you tried the following? Assuming you have amessages
resource configured in your route:EDIT: Above is deprecated. Rails 4.0 now accepts the prompt as a data attribute. See the doc here (Thanks @Ricky).
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.
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.
Next the link should have data-confirm & data-method attributes as
In erb, this can be written as,
This should work if everything is aligned in same fashion.
First, you should verify that your layout have jquery_ujs. Best practice to do it by including it in your main application.js:
Check that you included application.js in your layout:
While, in development mode, view your source html and verify jquery_ujs.js exists.
Run your server and verify your link tag has data-confirm value, for example:
If all those steps are correct, everything should work!
Note: check this RailsCast http://railscasts.com/episodes/136-jquery-ajax-revised