・ Rubis: 2.5.7 Rails: 5.2.4 ・ Vagrant: 2.2.7 -VirtualBox: 6.1 ・ Système d'exploitation: macOS Catalina
Ce qui suit a été mis en œuvre.
・ Mise en œuvre de la fonction de publication
| id | name | ancestry |
|---|---|---|
| 1 | Entreprise | nil |
| 2 | La finance | 1 |
| 3 | Stock | 1/2 |
| 4 | échange | 1/2 |
| 5 | impôt | 1/2 |
| 6 | Économie | 2 |
| 7 | Économie japonaise | 1/6 |
| 8 | Économie internationale | 1/6 |
| 9 | la gestion | 3 |
| 10 | Administration des affaires | 1/9 |
| 11 | Stratégie / Stratégie | 1/9 |
| 12 | Entreprise / ouverture | 1/9 |
| 13 | commercialisation | 4 |
| 14 | Administration des affaires | 1/13 |
| 15 | Stratégie / Stratégie | 1/13 |
| 16 | Entreprise / ouverture | 1/13 |
Si vous souhaitez que la catégorie de livre ait la relation parent-enfant ci-dessus, créez les données comme suit.
seed.rb
business = Category.create(name: 'Entreprise')
business_children_array = ['La finance', 'Économie', 'la gestion', 'commercialisation']
business_grandchildren_array = [
['Stock', 'échange', 'impôt'], #Enfant de la finance
['Économie japonaise', 'Économie internationale'], #Enfant de l'économie
['Administration des affaires', 'Stratégie / gestion', 'Démarrer une entreprise / démarrer une entreprise'], #Enfant du management
['La publicité', 'Ventes', 'développement de'] #Marketing enfant
]
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
Implémentation de la fonction de catégorie multicouche (formulaire de création)
Recommended Posts