Rails 假重命名控制器
标题可能有点误导,对此我深表歉意。我想做的就是 Reddit 如何为其子 Reddit 重命名控制器。他们使用 /r/programming 的形式,而不是更长的 /subreddit/programming。我知道他们不使用 Rails,但是我该如何使用 Rails 来做到这一点呢?
谢谢!
The title might be a little misleading, and I apologize for that. What I want to do is something like how Reddit renames their controller for their subreddits. They use the form /r/programming, instead of the longer /subreddit/programming. I know that they don't use Rails, but how would I go about doing that with Rails?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
为此,您可以在路由中使用匹配器。
在routes.rb
resources :subreddits, :path => 中“/r”
进一步阅读:http://guides.rubyonrails.org/routing.html< /a>
You can just use a matcher in your routing for this.
In routes.rb
resources :subreddits, :path => "/r"
Further Reading: http://guides.rubyonrails.org/routing.html