开发者

Rails, Restful Routes, and Awesome 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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜