Rails 3路由:避免深度嵌套 [英] Rails 3 routing: Avoiding Deep Nesting
问题描述
今天,我意识到我对嵌套资源感到有些迷惑:
Today I realised I'd gotten a little carried away with nested resources:
resources :organisations do
resources :studies do
resources :settings
end
end
Rails准则(以及我自己的想法)建议您嵌套的深度不应超过1层,因此我将其重构为:
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
有人知道这种路线的更简洁/更简洁的方法吗? Google给了我很多有关Rails 2的东西。
Does anyone know a cleaner / more concise way to declare the above routes? Google gave me a lot of Rails 2-specific stuff.
非常感谢!
推荐答案
您几乎已经弄清楚了它并走在正确的轨道上。这确实取决于您的域。仅查看您的路线,我会思考设置
的作用。也许可以在某处处理设置的命名空间就足够了,也许还不够。确实取决于您要执行的操作。
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。您还可以在Rails 3.0.X中参考路由。
PS. You can also refer to this guide for routing in Rails 3.0.X.
这篇关于Rails 3路由:避免深度嵌套的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!