开发者

Rails, Restful Routes, and Awesome Nested Set

开发者 https://www.devze.com 2022-12-08 05:36 出处:网络
I have a data structure that is basically a tree using :wesome nested set: class category acts_as_nested_set

I have a data structure that is basically a tree using :wesome nested set:

class category
  acts_as_nested_set

What I want to achieve are routes like

/categories/1/children/
/categories/1/children/new

I know I could fake it by making a separate controller, but开发者_如何学编程 it seems a bit non-DRY. Are there any better ways to do this?


Have you tried this:

map.resources :categories do |categories|
  categories.resources :children, :controller => :categories, 
                                  :only => [:index, :new, :create]
end

Then you'll have to check for params[:category_id] in CategoriesController#index, #new, and #create to see if it is the nested route.

0

精彩评论

暂无评论...
验证码 换一张
取 消