2011-04-14 66 views
0

使用RoR 2.3.8。在Rails中尋找更好的URL

想知道,有沒有辦法重新路由這樣的網址?

老:

http://localhost:3000/shops/16-white-cafe-house?type=cafes 

新:

http://localhost:3000/cafes/16-white-cafe-house 

回答

2

我能想到的一種方式,通過命名空間:

在Rails 3,我會做:

namespace 'cafe' do 
    match '/:cafe_name(.:format)', :to => 'shop#show', 
end 

哪個應該生成url:http://localhost:3000/cafe/16-white-cafe-house

也許你可以爲Rails 2.3.8的指南找到一個等效的代碼結構。

希望有幫助!