![](/img/trans.png)
[英]Rails 4 - Polymorphic associations with update action on nested polymorphic attributes
[英]Rails polymorphic link for nested index action
我一直试图找到这个链接几个小时了。 我有一个多态关联,其中两个集合和分类都有设计。
收集模型
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
也许这将有助于将来使用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.