Rails 3 路由:避免深层嵌套

发布于 2024-11-15 12:31:00 字数 400 浏览 4 评论 0原文

今天我意识到我对嵌套资源有点得意忘形了:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

擦肩而过的背影 2024-11-22 12:31:00

您几乎已经弄清楚了并且走上了正确的道路。这实际上取决于您的域。只要看看你的路线,我就会思考 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文