Rails 嵌套资源和 :path => “/”
我有以下路由,允许像 /:username/:project_name
这样的 url
resources :users, :path => "/" do
resources :projects, :path => "/"
end
问题是 /:username/edit
不起作用,因为它正在寻找名为“edit”的项目。
有什么办法解决这个问题吗?谢谢!
I have the following routes, which allows for urls like /:username/:project_name
resources :users, :path => "/" do
resources :projects, :path => "/"
end
The problem is that /:username/edit
doesn't work, because it is looking for a project with the name of 'edit'.
Any way around this? Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
有几种方法可以做到这一点...
1)会给你像
/:user_id/:id
这样的路由(你想要的)2)会给你像
/:user_id/projects/ 这样的路由:id
(你似乎在避免这样做)我个人更喜欢#2,因为它更干净,并且一目了然地提供了有关路线的更多信息。
A couple ways of doing this...
1) Will give you routes like
/:user_id/:id
(which you wanted)2) Will give you routes like
/:user_id/projects/:id
(which it seems like you're avoiding)I personally prefer #2 since it is cleaner and provides more knowledge about the route at a glance.