简体   繁体   English

在Rails中路由以获得更好的URL

[英]Routing in Rails for better URL

Using RoR 2.3.8. 使用RoR 2.3.8。

Wondering, is there a 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: 在rails 3中,我会这样做:

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

Which should generate urls like: http://localhost:3000/cafe/16-white-cafe-house 哪个应该生成网址: http:// localhost:3000 / cafe / 16-white-cafe-house

Perhaps you can dig up the Rails 2.3.8 guides for an equivalent code structure. 也许您可以挖掘Rails 2.3.8指南以获得等效的代码结构。

Hope that helps! 希望有所帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM