【发布时间】:2012-04-21 04:31:24
【问题描述】:
使用 Rails 3.1.1 和 gemacts_as_tree。我已经用谷歌搜索了这个问题并在 SO 上检查了类似的问题(答案太旧或不相关)。
我有一个名为 items 的模型,它的路线今天看起来像:
resources :articles, :path => '', :only => :show
resources :articles, :path => 'articles', :except => :show
我有三篇文章:“book”、“chapter1”和“chapter2”。 book 是第 1 章和第 2 章的父级。
今天,我每篇文章的路径是:host.com/book、host.com/chapter1 和 host.com/chapter2。我希望 url 路径是 host.com/book/chapter1 和 host.com/book/chapter2 ,即嵌套路由。
如何以简洁明了的方式创建它?
基本上,我想要一个路径为 host.com/:parent_id/:parent_id/:id 和 N 个 :parent_id。几乎是 Wordpress 文章的路由方式。
我不相信路由 globbers 是解决方案,但我可能错了。 host.com/:id 和 host.com/foo/bar/:id 似乎给出了相同的结果,这将导致重复的内容。
【问题讨论】:
标签: ruby-on-rails nested-routes acts-as-tree