0

I have a problem with my delete action and link. Here is my link :

<%= link_to 'Supprimer la thématique', @theme, method: :delete, data: { confirm:'Êtes-vous sûr de vouloir supprimer la thématique' }, :class => "btn btn-default" %>

And I don't know why, but this link redirect to the show action of my model 'theme'.

I can resolve this by using button_to but with a button_to I'm not able to set a data confirm :

<%= button_to "Supprimer la thématique", @theme, :method=>:delete, data: { confirm: 'Êtes-vous sûr de vouloir supprimer la thématique ?'}, :class=> 'btn btn-default' %>

Do you have any ideas why the link to doesn't redirect to the delete action or why I can't have a data confirm for my button_to ?

Simon M.
  • 2,244
  • 3
  • 17
  • 34

1 Answers1

0

Clicking a link always sends a GET request, unless there's Javascript in place that does something different, such as sending an Ajax request or submitting a hidden form. When using regular resourceful routes, the show action and destroy action share a route, and determine what to do based on the method (as you probably know).

The button_to method should support a confirmation dialog; if it doesn't work, then there's probably some Javascript missing.

Both your problems point to a missing unobtrusive Javascript driver. If using jquery-rails (the standard option), make sure that it's listed in your Gemfile:

gem 'jquery-rails'

and that you're loading it in your application.js:

//= require jquery
//= require jquery_ujs

Also be sure that you're calling the javascript_include_tag method in your application layout. Once you've got jquery-rails loaded properly, you should be able to get the results you're looking for with either method you've attempted.

For more information on loading jquery-rails, see the Github repo.

Wally Altman
  • 3,535
  • 3
  • 25
  • 33