# Multiple Nested Resources + named routes

**URL:** <https://www.ruby-forum.com/t/multiple-nested-resources-named-routes/108677>\
**Category:** Rails\
**Created:** [July 5, 2007, 11:16pm UTC](https://www.ruby-forum.com/t/multiple-nested-resources-named-routes/108677 "2007-07-05T23:16:28Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![AryaAsemanfar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/35a633/32.png) [@AryaAsemanfar](https://www.ruby-forum.com/u/AryaAsemanfar)\
**Post date:** [July 5, 2007, 11:16pm UTC](https://www.ruby-forum.com/t/multiple-nested-resources-named-routes/108677/1 "2007-07-05T23:16:28Z")

</div>

Hello,

I’m not sure if this has been answered before but I couldn’t find  
anything in the few searches I did before posting.

Anyway, here is what I’m trying to do:

I have 3 resources: One, Two, and Three

map.resources :ones do |ones|  
ones.resources :threes, :name\_prefix =\> “one\_”  
end

map.resources :twos do |twos|  
twos.resources :threes, :name\_prefix =\> “two\_”  
end

map.resources :threes

Now, in my controllers and views, I can access the following three  
sets of URL helpers (or named routes):  
one\_threes\_path  
two\_threes\_path  
threes\_path

Now my question is how do _cleanly_ determine which path method to  
use?

What I’ve done is defined in my Three controller a method called  
“determine\_threes\_path” and it looks like this:

def determine\_threes\_path  
eval “#{path\_method\_prefix}threes\_path”  
end

and path\_method\_prefix is a method that determines the value “one\_”,  
“two\_”, or “” depending on the values in the params hash.

I’ve done this for all the path methods that I need and then defined  
them all as helper methods so they are accessible in the view as well.

Is there an existing solution to this problem or does anyone have any  
suggestions on how I can do this in a more structured fashion?

Thank you in advanced for any help anyone can provide.
