[英]Custom profile URL or routing
Rails 3.2 app Rails 3.2应用
How do I access (read, show action) a resource with a custom URL? 如何使用自定义URL访问(阅读,显示操作)资源?
Typically we would do this (REST): 通常,我们会这样做(REST):
http://localhost/entities/23
and this will show the data for Entity with id = 23 这将显示id为23的实体的数据
How can have it going to the same page when using accessing this way: 使用这种方式访问时如何将其转到同一页面:
http://127.0.0.1/directory/[entity-name]
Is that something I can code in my routes.rb file? 我可以在routes.rb文件中编写代码吗?
Note that I want to replace spaces in Entity name with '-' in the URL. 请注意,我想用URL中的“-”替换实体名称中的空格。
Cheers, 干杯,
joel 乔尔
What you're looking for is slugged or human-friendly urls. 您正在寻找的是迟钝的网址或对人类友好的网址。
Friendly ID is a great gem which can help you create slugged urls. 友好ID是一个很棒的宝石,可以帮助您创建缓慢的网址。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.