0

我试图弄清楚如何获得这样的嵌套路由:

match '/:category_id/:subcategory_id/:id', via: 'get', controller: 'categories', action: 'index', as: 'category'

子类别和 id 不应该是必需的。应该可以得到:

  • 类别索引
  • 子类索引
  • 身份证显示

类别和子类别应使用相同的控制器操作。类别和子类别当然使用相同的祖先/树模型。

我对这个有点迷失了。任何提示都会很棒!

4

1 回答 1

0

It sounds like nested resources would get you most of what you want:

resources :category do 
  resources :subcategory 
end 

Have you considered/tried this?

For more on nested resources, including some insight into how to restrict what routes are exposed: http://guides.rubyonrails.org/routing.html#nested-resources

于 2013-03-12T14:21:41.130 回答