Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails link_to destroy a nested resource?

I have a nested resource attachments and I want to create a link_to to destroy/delete the attachment. Here's what I have, but it is posting as a GET versus a PUT:

<%= link_to "Delete Attachment", project_thread_attachment_path(@attachment.thread.project.id, @attachment.thread.id, @attachment.id), :confirm => "Are you sure you want to delete this attachment?", :method => :delete, :action => "destroy" %>

Ideas? Thanks!

like image 833
AnApprentice Avatar asked Feb 09 '11 01:02

AnApprentice


2 Answers

Try

link_to "Delete Attachment", [@attachment.thread.project,@attachment.thread,@attachment], :confirm => "Are you sure?", :method => :delete

Does it work?

like image 121
Gerry Avatar answered Sep 20 '22 15:09

Gerry


You should be able to use the following by itself (remove the :action => 'destroy' part). Also, the request should be a DELETE request, not a PUT request:

<%= link_to "Delete Attachment", project_thread_attachment_path(@attachment.thread.project.id, @attachment.thread.id, @attachment.id), :confirm => "Are you sure you want to delete this attachment?", :method => :delete %>
like image 23
Pan Thomakos Avatar answered Sep 18 '22 15:09

Pan Thomakos