Rails 嵌套资源,带有 response_with 销毁操作 [英] Rails nested resource with respond_with destroy action

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

问题描述

嵌套资源销毁操作的适当 respond_with 行是什么?

What is the appropriate respond_with line for a nested resources destroy action?

我的路线:

resources :vendors do
  resources :products, :except => [:index]
end

Product#destroy(注意 @vendor@productbefore_filter 一起发现,此处省略)

Product#destroy (note @vendor and @product are found with a before_filter which is omitted here)

def destroy
  @product.destroy 
  respond_with @vendor, @product
end

根据我的功能测试,这是返回 /vendors/X/products/X 而不是 /vendors/X

According to my functional tests, this is returning /vendors/X/products/X and not /vendors/X

我应该将其更改为 responed_to @vendor 吗?

Should I change it to just responed_to @vendor?

推荐答案

我相信 Rails 足够聪明,可以理解如果@product 被破坏了该怎么办

I believe Rails is smart enough to understand what to do if @product is destroyed

respond_with [@vendor, @product]

如果没有,那就试试这个

if not, then try this

respond_with @product, :location => vendor_path(@vendor)

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

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