With rails 2.3.8 I had
= link_to 'old_Delete', link_path(@link), :confirm => 'Are you sure?',
:method => :delete
With rails 3.1.8 this no longer works, no error and the log just shows a show request.
I tried changing it to
= link_to 'Delete', link_path(@link), method: :delete,
data: { :confirm => 'Are you sure?' }
but that didn’t help either.
How can I have a delete link that works.
I created a new app (rails 3.2.7) with a ‘post’ resource to see how links look in a new app.
The link generated for that was:
= link_to 'Destroy', post, method: :delete, data: { confirm: 'Are you sure?' }
but when I try to use that format, replacing post (Post resource, model, etc.) with @link, the link instance that I am using elsewhere on the page, i.e.
= link_to 'Destroy', @link, method: :delete, data: { confirm: 'Are you sure?' }
It doesn’t work (no error).
I tried saving rails.js in my public/javascripts folder (I have assest compilation turned off) and including config.action_view.javascript_expansions[:defaults] = %w(jquery rails) in my config/application.rb but it didn’t help, still seeing gets and no deletes happening.
As others have said you probably have a typo,
linkvs@link. But the reason the delete stopped working is probably centered around the change to UJS. Long answer, google “rails change to ujs in 3.0”. Short answer, make sure your app is loadingrails.jsfrom an appropriate ujs helper provider, such as https://github.com/rails/jquery-ujsMake sure that, along with your other changes you change:
to