Search code examples
ruby-on-railsrubyruby-on-rails-4link-to

Using :confirm in my link_to helper method in ruby on rails 4 has no effect what so ever. What could be wrong?


This is my link_to method:

<%= link_to 'Dispatch Now', order_path(order["objectId"]), :method => 'delete', :confirm => 'Are you sure?' %>

I've looked at my old ruby on rails 3 projects and this is how I've called confirm in my link_to helpers.

It doesn't seem to have any effect.

Has something changed with ruby on rails 4 that would have caused this to stop working? I have the jquery-rails file in my gemfile and I've checked my application.js file and everything looks fine.

What could be wrong?


Solution

  • You'll need to use:

    <%= link_to "Delete", path, method: :delete, data: { confirm: "Are you sure?"} %>
    

    --

    Rails 4 changed the syntax, so that the confirm attribute is now handled in the data hash. Whereas before you could get away with confirm:, now you have to manage data: { confirm: "your_confirmation" }