Named nested resource routes/polymorphic relationships

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

On 1/22/07, Ingo W. [email protected] 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