Rails link_to 销毁嵌套资源? [英] Rails link_to destroy a nested resource?

查看:35
本文介绍了Rails link_to 销毁嵌套资源?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个嵌套的资源附件,我想创建一个 link_to 来销毁/删除附件.这是我所拥有的,但它是作为 GET 与 PUT 发布的:

<%= link_to "删除附件", project_thread_attachment_path(@attachment.thread.project.id, @attachment.thread.id, @attachment.id), :confirm =>"您确定要删除此附件吗?", :method =>:delete, :action =>摧毁"%>

想法?谢谢!

解决方案

您应该能够单独使用以下内容(删除 :action => 'destroy' 部分).此外,请求应该是 DELETE 请求,而不是 PUT 请求:

<前><%= link_to "删除附件", project_thread_attachment_path(@attachment.thread.project.id, @attachment.thread.id, @attachment.id), :confirm => "你确定要删除这个附件吗?", :method => :delete %>

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!

解决方案

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 %>

这篇关于Rails link_to 销毁嵌套资源?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆