Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails polymorphic link for nested index action

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

Collection model

has_many :designs, :as => :targetable

Assortment model

has_many :designs, :as => :targetable

Design model

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??

like image 975
Justin Avatar asked Dec 17 '13 01:12

Justin


1 Answers

I was finally able to find the answer.

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.

like image 89
Justin Avatar answered Nov 08 '22 16:11

Justin