3

我一直在試圖找到這個鏈接幾個小時。我有一個多態協會,其中兩個收藏品&分類都有設計。嵌套索引操作的Rails多態鏈接

收集模型

has_many :designs, :as => :targetable 

拼盤模式

has_many :designs, :as => :targetable 

設計模型

belongs_to :targetable, :polymorphic => true 


爲了鏈接到設計」 S「秀」的動作,適當的多態路徑將是:

link_to polymorphic_path([@targetable, @design]) 

但我無法弄清楚如何鏈接到設計的「索引」頁面,以顯示與它的各自定位的對象相關聯的所有設計。

有誰知道適當的鏈接?

回答

6

我終於能夠找到答案。

polymorphic_path([@targetable, Design]) 

而不是使用變量作爲多態路徑中的第二個對象,應該使用模型名稱。此路徑鏈接到

targetable/:targetable_id/designs 

也許這會幫助某人將來使用。

+1

這是黃金!謝謝! – Tashows