Named route with nested resources

蓝咒 提交于 2019-12-11 16:02:59

问题


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:


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


来源:https://stackoverflow.com/questions/2370882/named-route-with-nested-resources

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!