2010-10-24 52 views
0

我要为我UserController的以下网址:我想下面的网址模式,请帮我用导轨3

localhost/user/join 
localhost/user/login 
localhost/user/user_name (this can be any name in here, it should fire the 'profile' action) 

然后/用户/ user_name_here /文件夹中的我想:

/user/user_name/blah1/ 
/user/user_name/blah2/ 
/user/user_name/blah3/ 

它似乎在做资源:用户只创建索引/显示/获取的东西,所以我很困惑如何做到这一点,而不是在路线中创建如此多的线路。

回答

2
match "user/:user_name" => "users#show" 

然后/用户/用户名会重定向到用户控制器,调用Show方法,并传递:USER_NAME PARAM

,你可以做同样的是不啃老族参数等动作,

match '/user/login' => "sessions#new" 
match '/user/join' => "user#new" 
0

是 - '资源:用户'只是通常的CRUD方法的脚手架。如果你想要的路径不是那些,你将不得不创建路线(这是你的应用知道如何将给定的URL路由到给定的控制器和方法的唯一方式)。

friendly_id gem做了类似于你的建议(虽然我相信它是猴子修补ActiveRecords类的.find方法,而不是专门处理路由)。