Rails多态链接,用于嵌套索引操作 [英] Rails polymorphic link for nested index action

查看:54
本文介绍了Rails多态链接,用于嵌套索引操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经尝试了好几个小时了.我有一个多态关联,其中两个集合&各式各样都有设计.

I have been trying to find this one link for hours now. I have a polymorphic association where both collections & assortments have designs.

收集模型

has_many :designs, :as => :targetable

分类模型

has_many :designs, :as => :targetable

设计模型

belongs_to :targetable, :polymorphic => true


为了链接到设计的显示"动作,正确的多态路径应为:

In order to link to the design's 'show' action, the proper polymorphic path would be:

link_to polymorphic_path([@targetable, @design])

但是我不知道如何链接到设计的索引"页面以显示与其各自的可定位对象相关的所有设计.

But I can't figure out how to link to the design's 'index' page to show all the designs associated with it's respective targetable object.

有人知道到达那里的合适链接吗?

Does anyone know the appropriate link to get there??

推荐答案

我终于能够找到答案.

polymorphic_path([@targetable, Design])

您应该使用模型名称,而不是将变量用作多态路径中的第二个对象.该路径链接到

Instead of using a variable as the second object in the polymorphic path, you are supposed to use the model name. This path links to

targetable/:targetable_id/designs

也许这会帮助某人将来使用.

Maybe this will help someone for future use.

这篇关于Rails多态链接,用于嵌套索引操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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