R
R
Roman Volkov2015-05-05 17:57:11
MySQL
Roman Volkov, 2015-05-05 17:57:11

How to make a multi-level category model?

The task is to create a category model (name, description) - this is not a problem. The question is how to create a relationship between the two categories "Parent"->"Child". At the same time, make multi-level categories, for example
Clothing
- Children's clothing
- hats
- shoes
- Women's clothing
- Sweatshirts
, etc.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
R
Renat Ibragimov, 2015-05-07
@white_wolf_17

For example, a model where there is a parent_id pointing to the parent (for root it is nil)

class Category < ActiveRecord::Base
  has_closure_tree
  acts_as_tree
end

+ gem closure_tree

V
Viktor Vsk, 2015-05-05
@viktorvsk

https://www.ruby-toolbox.com/categories/Active_Rec...
awesome-ruby.com/ (Tree: Ancestry ...)

R
Robert, 2015-05-06
@Jowan

Alternatively:
You have your global category model which has_many some private categories. They, in turn, have_many already specific goods.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question