・ Ruby: 2.5.7 Rails: 5.2.4 ・ Vagrant: 2.2.7 -VirtualBox: 6.1 ・ OS: macOS Catalina
The following has been implemented.
・ Implementation of posting function -Many-to-many category function implementation ・ Multi-layer category function implementation (preparation)
id | name | ancestry |
---|---|---|
1 | business | nil |
2 | Finance | 1 |
3 | stock | 1/2 |
4 | exchange | 1/2 |
5 | tax | 1/2 |
6 | Economy | 2 |
7 | Japanese economy | 1/6 |
8 | International economy | 1/6 |
9 | management | 3 |
10 | Business Administration | 1/9 |
11 | Strategy / Strategy | 1/9 |
12 | Company / Opening | 1/9 |
13 | marketing | 4 |
14 | Business Administration | 1/13 |
15 | Strategy / Strategy | 1/13 |
16 | Company / Opening | 1/13 |
If you want the book category to have the above parent-child relationship, create the data as follows.
seed.rb
business = Category.create(name: 'business')
business_children_array = ['Finance', 'Economy', 'management', 'marketing']
business_grandchildren_array = [
['stock', 'exchange', 'tax'], #Financial child
['Japanese economy', 'International economy'], #Child of economy
['Business Administration', 'Strategy / management', 'Entrepreneurship / opening'], #Child of management
['Advertising', 'Sales', 'development of'] #Marketing child
]
business_children_array.each_with_index do |children, index|
children = business.children.create(name: children)
business_grandchildren_array[index].each do |grandchildren|
children.children.create(name: grandchildren)
end
end
Multi-layer category function implementation (creation form)
Recommended Posts