Hi all, my app manages assignments and deliverables and I have a polymorphic relationship between ''deliverables'' and ''assignments'' where deliverables can belong_to either assignments or sub-assignments. As a result, I need deliverables to appear in two places in my nested resource routes: assignment.resources :deliverables assignment.resources :sub_assignments do |sub_assignment| sub_assignment.resources :deliverables end Now what I was hoping for is that named routes would work like this: deliverables_path(@assignment) => ''/assignments/1/deliverables'' deliverables_path(@assignment, @sub_assignment) => ''/assignments/1/sub_assignments/1/deliverables'' Instead I get an ''url failed to be generated'' error. It works fine if I use url_for instead. Now this is pretty much just an inconvenience, but I was wondering if there is a better way of if I can somehow get named routes to work with this model. Thanks for any help! Ingo -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Rick Olson
2007-Jan-22 18:32 UTC
Re: named nested resource routes/polymorphic relationships
On 1/22/07, Ingo Weiss <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > Hi all, > > my app manages assignments and deliverables and I have a polymorphic > relationship between ''deliverables'' and ''assignments'' where deliverables > can belong_to either assignments or sub-assignments. As a result, I need > deliverables to appear in two places in my nested resource routes: > > assignment.resources :deliverables > assignment.resources :sub_assignments do |sub_assignment| > sub_assignment.resources :deliverables > end > > Now what I was hoping for is that named routes would work like this: > > deliverables_path(@assignment) > => ''/assignments/1/deliverables'' > > deliverables_path(@assignment, @sub_assignment) > => ''/assignments/1/sub_assignments/1/deliverables'' > > Instead I get an ''url failed to be generated'' error. It works fine if I > use url_for instead. > > Now this is pretty much just an inconvenience, but I was wondering if > there is a better way of if I can somehow get named routes to work with > this model. > > Thanks for any help!Named routes are basically like methods, so no, it''s not possible. You''ll have to use the :name_prefix option. -- Rick Olson http://weblog.techno-weenie.net http://mephistoblog.com --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---