2010-10-24 54 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方法,而不是專門處理路由)。