Tiago
Tiago

Reputation: 2966

Named route with nested resources

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 :)

Upvotes: 0

Views: 627

Answers (1)

xijo
xijo

Reputation: 4366

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

Upvotes: 1

Related Questions