Forum: Ruby on Rails named nested resource routes/polymorphic relationships

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Ingo W. (Guest)
on 2007-01-22 19:34
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
Rick O. (Guest)
on 2007-01-22 20:33
(Received via mailing list)
On 1/22/07, Ingo W. <removed_email_address@domain.invalid> wrote:
>   sub_assignment.resources :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 O.
http://weblog.techno-weenie.net
http://mephistoblog.com
This topic is locked and can not be replied to.