Rails link_to销毁嵌套资源?

时间:2011-02-09 01:26:40

标签: ruby-on-rails ruby-on-rails-3

我有一个嵌套的资源附件,我想创建一个link_to来销毁/删除附件。这就是我所拥有的,但它是作为GET发布而不是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" %>

想法?谢谢!

2 个答案:

答案 0 :(得分:15)

尝试

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

有效吗?

答案 1 :(得分:8)

您应该能够自己使用以下内容(删除:action =&gt;'destroy'部分)。此外,请求应该是DELETE请求,而不是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 %>