开发者

Named route with nested resources

开发者 https://www.devze.com 2022-12-21 15:56 出处:网络
I\'m trying to make a named route \'have_many\' other named routes here. But the way I\'m doing it\'s not working.

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 =开发者_JAVA百科> :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 :)


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
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号