【问题标题】:Rails polymorphic link for nested index action用于嵌套索引操作的 Rails 多态链接
【发布时间】:2013-12-17 01:23:47
【问题描述】:

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

集合模型

has_many :designs, :as => :targetable

分类模型

has_many :designs, :as => :targetable

设计模型

belongs_to :targetable, :polymorphic => true


为了链接到设计的“展示”动作,正确的多态路径应该是:

link_to polymorphic_path([@targetable, @design])

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

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

【问题讨论】:

    标签: ruby-on-rails ruby-on-rails-4 nested-attributes polymorphic-associations


    【解决方案1】:

    我终于找到了答案。

    polymorphic_path([@targetable, Design])
    

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

    targetable/:targetable_id/designs
    

    也许这会对某人将来的使用有所帮助。

    【讨论】:

    • 这是金子!谢谢!
    • 太棒了,非常感谢。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-12-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多