用于嵌套索引操作的Rails多态链接

我一直试图找到这个链接几个小时。 我有一个多态关联,其中的集合和分类都有设计。

收集模型

has_many :designs, :as => :targetable 

分类模型

 has_many :designs, :as => :targetable 

设计模型

 belongs_to :targetable, :polymorphic => true 

为了链接到设计的“show”动作,正确的多态路径将是:

 link_to polymorphic_path([@targetable, @design]) 

但我无法弄清楚如何链接到设计的“索引”页面,以显示与其相应的可定位对象相关的所有设计。

有谁知道到达那里的适当链接?

我终于找到了答案。

 polymorphic_path([@targetable, Design]) 

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

 targetable/:targetable_id/designs 

也许这将有助于将来使用。