Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails :confirm does not show dialog box

I have a rails app with the following code in one of my views:

<% if @present.taken == false %>
    <%= link_to "I want to buy this present", :confirm => 'Are you sure you want to buy this present?', :action => "taken_toggle", :id => @present.id %>
<% end %>

However, I don't get a javascript dialog box showing - it just seems to skip that bit (the calling of the action works).

My application layout has the following:

  <%= stylesheet_link_tag :all %>
  <%= javascript_include_tag :defaults %>
  <%= csrf_meta_tag %>

So I think I have the necessary javascript loaded.

Any ideas why this isn't working?

like image 362
robintw Avatar asked Dec 28 '25 16:12

robintw


1 Answers

As the documentation shows

http://api.rubyonrails.org/classes/ActionView/Helpers/UrlHelper.html#method-i-link_to

in

Be careful when using the older argument style, as an extra literal hash is needed:

try using like this

<% if @present.taken == false %>
    <%= link_to "I want to buy this present", { :action => "taken_toggle"}, :confirm => 'Are you sure you want to buy this present?', :id => @present.id %>
<% end %>
like image 68
Felipe Sabino Avatar answered Dec 30 '25 07:12

Felipe Sabino



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!