Reputation: 3259
I'm building a Ruby on Rails application and I have generated some scaffold. I want to add a confirmation box (like the one that pops up when you delete an element) to a custom link I created.
The syntax for the element deletion is the following:
<td><%= link_to 'Destroy', user, method: :delete, data: { confirm: 'Are you sure?' } %></td>
This is my custom link:
<td><%= link_to 'set done', :controller => 'users', :action => 'set_donation_done', :user => user, data: { confirm: 'Are you sure?' } %><td>
The problem is that the confirmation box on my custom link does not appear. If I inspect the element I see the following html code:
<a href="/set_donation_done?data%5Bconfirm%5D=Are+you+sure%3F&user=71">set done</a>
What am I doing wrong?
Upvotes: 1
Views: 864
Reputation: 3259
Found the solution:
<td><%= link_to 'set done', {:controller => 'users', :action => 'set_donation_done', :user => user}, data: { confirm: 'Are you sure?'} %><td>
Whit this formula I have my user data in params and I can see the confirmation box!
Upvotes: 1
Reputation: 2088
You don't need the controller action hash. Simply show when the HTML hash starts like so:
<td><%= link_to 'Destroy', user, method: :delete,{ data: { confirm: 'Are you sure?' }} %></td>
Upvotes: 0
Reputation: 3042
Try with this:
<%= link_to 'set done', { controller: 'users', action: 'set_donation_done' }, user: user, data: { confirm: 'Are you sure?' } %>
Remember:
link_to(body, url_hash, html_hash)
http://apidock.com/rails/ActionView/Helpers/UrlHelper/link_to
Upvotes: 2