Rails 3 路由:避免深层嵌套
今天我意识到我对嵌套资源有点得意忘形了:
resources :organisations do
resources :studies do
resources :settings
end
end
Rails 指南(和我自己的想法)建议你嵌套的深度不应超过 1 层,所以我重构了这一点:
resources :organisations do
resources :studies
end
resources :studies do
resources :settings
end
有谁知道一个更干净/更多的资源吗?声明上述路由的简洁方法? Google 给了我很多 Rails 2 特有的东西。
非常感谢!
Today I realised I'd gotten a little carried away with nested resources:
resources :organisations do
resources :studies do
resources :settings
end
end
The Rails guidelines (and my own thoughts) suggest that you shouldn't nest more than 1 level deep, so I refactored to this:
resources :organisations do
resources :studies
end
resources :studies do
resources :settings
end
Does anyone know a cleaner / more concise way to declare the above routes? Google gave me a lot of Rails 2-specific stuff.
Many thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您几乎已经弄清楚了并且走上了正确的道路。这实际上取决于您的域。只要看看你的路线,我就会思考
Settings
的作用。也许在某个地方有一个命名空间来处理设置就足够了,也许还不够。真的取决于你想做什么。然而,就嵌套而言。看起来不错。
附言。您还可以参阅本指南以了解 Rails 3.0.X 中的路由。
You pretty much got it figured out and on the right track. It really depends on your domain. Just looking at your routes, I would ponder on what
Settings
does. Maybe a namespace somewhere to handle settings would suffice, maybe not. Really depends on what you are trying to do.However, as far as nesting goes. It's looking fine.
PS. You can also refer to this guide for routing in Rails 3.0.X.