Rails 路由,我将如何创建这种 slug 式路由?
我正在尝试创建一个如下所示的网址:
www.example.com/something/:a_slug
所以一个网址是/某物,其中某物不是控制器(但它映射到控制器,如控制器别名)。某事是一个固定的词。
然后 :a_slug 可以是传递到控制器并在操作中拾取的任何 slug。
有点像非常自定义的显示资源 url。
看起来很简单,但我似乎无法找到正确的路线。
干杯!
I'm trying to create a url that looks like this:
www.example.com/something/:a_slug
So a url that is /something where something is not a controller (but it is mapped to a controller, like a controller alias). Something is a fixed word.
Then :a_slug can be any slug passed into the a controller and picked up on an action.
Sort of a very custom show resource url.
It seems simple but I can't seem to get the route right.
Cheers!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
routes.rb
app/controllers/widgets_controller.rb
就像魔术一样,
GET /something/feh
显示feh
在浏览器中。哦,当然这是针对 Rails 3 的。 Rails 2 类似,但您没有在那里指定要求。
routes.rb
app/controllers/widgets_controller.rb
And as if by magic,
GET /something/feh
showsfeh
in the browser.Oh, of course this is for rails 3. It's similar for rails 2 but you didn't specify a requirement there.