
1. 手順
1.1. 新規登録画面での実装
1.1.1. ancestryに関わるモデルへの記述
1.1.1.1. has ancestry
1.1.2. ancestry gemのインストール
1.1.3. seed.rbファイルの作成
1.1.3.1. seeds.rbでデータを読み込み
1.1.4. routingの設定
1.1.4.1. collection do
1.1.5. controllerの設定
1.1.5.1. get_category_children
1.1.5.1.1. カテゴリーの親要素.childrenで子要素を生成
1.1.5.2. get_category_grandchildren
1.1.5.2.1. カテゴリーの子要素.childrenで孫要素を生成
1.1.5.3. def_set_category
1.1.5.3.1. privateにおいて
1.1.6. JSファイルの作成
1.1.6.1. category.js
1.1.7. json.builderの作成
1.1.7.1. @category_childrenの定義
1.1.7.2. @category_grandchildrenの定義
1.1.8. フロントの実装
1.1.8.1. f.collection_selectの使用
1.1.8.1.1. f.collection_selectとは
1.2. 商品編集画面での実装
1.2.1. routingの調整
1.2.1.1. collection do
1.2.2. controllerの調整
1.2.2.1. editアクション追記
1.2.2.1.1. ポイント:item情報にはcategory_idの孫要素のみ保存されている
1.2.2.1.2. 子要素、親要素を取得
1.2.2.1.3. 孫、子の配列を生成
1.2.3. JSファイルの調整(必要であれば)
1.2.3.1. urlのパスが相対パスであれば、エラーが発生する恐れ
1.2.4. フロントの調整
1.2.4.1. 条件分岐でセレクトボックスの表示を調整
1.2.4.1.1. -if, -elsif