views:

128

answers:

1

I'm trying to make a named route 'have_many' other named routes here. But the way I'm doing it's not working.

Here is my problem: I've several game platforms that I want to access by /:platform_name/. This is working:

map.platform ':platform_name', 
              :controller => :platforms, 
              :action => :index,
              :platform_name => /pc|ps2|ps3|wii|ds|psp|xbox360/

But I also have games inside each platform, that I want to refer by name, so I've tried:

map.platform ':platform_name', 
                  :controller => :platforms, 
                  :action => :index,
                  :platform_name => /pc|ps2|ps3|wii|ds|psp|xbox360/ do |platform|

   platform.games ':game_name',
                  :controller => :games
end

But when I do this, even the platform route stop working. Is it possible to have a named route inside other named route? I can only imagine a dirty code to achieve this without the has_many relation. Any idea is welcome :)

+1  A: 

Hi Tiago,

I'm not sure if this is what you want but what about nesting through 2 named routes?

map.platform ':platform_name', :controller => :platforms, :action => :index

map.games ':platform_name/:game_name', :controller => :games, :action => :show
Joe
yeah, that works, but games will have more named routes inside, like comments, reviews... isn't there a cleaner way maybe?
Tiago
Then I suggest to use RESTful-resource routing, take a look at http://guides.rubyonrails.org/routing.html. btw Jamis Buck says: "Resources should never be nested more than 1 level deep." - which is a good convention!
Joe