Handle categories and (nested) resources

9 views
Skip to first unread message

Linus Pettersson

unread,
Dec 2, 2011, 1:21:05 PM12/2/11
to rubyonra...@googlegroups.com
I have an application, built with Rails 3.1.3, that has products and categories. The categories are related to other categories, so a category can be a parent or a child category. The products are then related to a child category.

Now, I'm thinking about how I should define the routes. Is it a good idea to somehow nest the categories and products resources? Ideally, I would like URLs like this:
    
    
    like this:

    or maybe like this to keep it restful?

But maybe that's a bit messy to achieve with the routes? I would have to nest the category with itself I guess?

Any ideas on how to achieve something like this?


Do I create the category routes like this:

    resources :categories, :as => "parent" do
        resources :categories, :as => "child"
    end

or similar?
It's not that important to have the product nested inside the categories. Maybe it will just make it hard to manage...

Linus Pettersson

unread,
Dec 2, 2011, 5:27:12 PM12/2/11
to rubyonra...@googlegroups.com
Maybe it is better to just create two models/controllers and nest them? That way I get restful routes easily.
Reply all
Reply to author
Forward
0 new messages