Riding Rails
Riding Rails

Reputation: 23

I can't get link_to for deleting to work in my app [RoR]

I have tried to get this working with multiple different variations and it refuses to delete it. The box comes up asking me to confirm and when I do it takes me to the main show for that controller. I have tried link_to in multiple contexts for different controllers but none of them work. Oddly enough I had it working for a while and I'm not sure what I changed to cuase it to stop working again.

<%= link_to 'Delete Review', review, :method => "delete", :onclick => "return confirm('Are you sure you want to delete this review?')" %>

<%= link_to 'Delete Review',  review,  method: :delete, data: { confirm: 'Are you sure?' } %>

These are both of the ones I tried.

Upvotes: 0

Views: 63

Answers (2)

sevenseacat
sevenseacat

Reputation: 25029

Check if you have included jquery_ujs in your application.js manifest - removing Rails' JS code will stop things like delete links (and also things like forms with remote: true) from working.

Alternatively, Javascript errors will interfere with the Rails' javascript handlers.

Upvotes: 0

Joseph N.
Joseph N.

Reputation: 2457

What is the context of review?. You should pass a valid url as the second parameter.

E.g for your case you could do something like

<%= link_to "Delete Review", review_path(@review), method: :delete, data: { confirm: 'Are you sure?' } %>

Hope that helps

Upvotes: 1

Related Questions