开发者

Routing in Rails for better URL

开发者 https://www.devze.com 2023-02-24 07:53 出处:网络
Using RoR 2.3.8. Wondering, is there a开发者_JS百科 way to re-route such url? Old: http://localhost:3000/shops/16-white-cafe-house?type=cafes

Using RoR 2.3.8.

Wondering, is there a开发者_JS百科 way to re-route such url?

Old:

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

New:

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


I can think of one way, via namespace:

In rails 3, I would do:

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

Which should generate urls like: http://localhost:3000/cafe/16-white-cafe-house

Perhaps you can dig up the Rails 2.3.8 guides for an equivalent code structure.

Hope that helps!

0

精彩评论

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

关注公众号