Rails 嵌套 URL 问题

发布于 2024-09-01 06:39:09 字数 249 浏览 0 评论 0原文

我在 Rails 中遇到 RESTful URL 问题。

我有 site.com/services url,我想在该类别下有子页面,就是这样:site.com/services/arquitecture、site.com/services/plumbing 等。

我在该类别下提供的页面是“ static”.rhtml 文件,我希望它们位于同一控制器上。

有办法做到这一点吗?我尝试过嵌套资源,但发现很难完全理解。

谢谢

Im having issues with RESTful URLs in Rails.

I have site.com/services url, and I want to have subpages under that category, thats it: site.com/services/arquitecture, site.com/services/plumbing, etc.

The pages that im serving under that category are "static" .rhtml files and I would want them to be on the same controller.

Is there a way of doing this? I've tried nested resources but I find it hard to fully understand.

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

慈悲佛祖 2024-09-08 06:39:09

资源不是为提供静态页面而构建的。使用常规的非 RESTful 路由,您可以准确定义哪些 URL 映射到哪个控制器和操作。

Resources weren't built for serving static pages. Use regular, non-RESTful routes where you can define exactly which URLs maps to which controller and action.

对不⑦ 2024-09-08 06:39:09

这是一种简单的方法。

假设您的routes.rb中有一个“服务”资源,则不需要嵌套资源 - 只需将 :members 哈希添加到您的路由定义中:

map.resources :services, :member => {:plumbing => :get, :arquitecture => :get, ...}

然后在服务控制器中为每个静态页面定义空操作。如果这些页面确实是静态的并且是静态的,则可以对它们使用页面缓存。在第一次调用每个操作后,Rails 将完全绕过控制器。

Here is one simple approaches for this.

Assuming you have a "services" resource in your routes.rb, you don't need nested resources - just add a :members hash to your route definition:

map.resources :services, :member => {:plumbing => :get, :arquitecture => :get, ...}

then define empty actions in your services controller for each static page. You can use page caching for those pages if they are truly static & Rails will bypass the controller altogether after the 1st call to each action.

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