###やりたいこと
多階層カテゴリで、子カテゴリのnameをセレクトで出力したい
親カテゴリである第1回の子カテゴリがA,Bチームです
カテゴリーテーブル
id name ancestry
1 第1回 NULL
2 Aチーム 1
3 Bチーム 1
###NoMethodError
以下であると、親カテゴリは@parentsで出力できているのですが
子カテゴリを出力しようと、@parents.childrenとすると、undefined method `children' for #Category::ActiveRecord_Relation:0x00007fb4d4147630が発生します
def new @tweet=Tweet.new @parents = Category.where(ancestry: nil) end
<%= f.label "大会選択" %> <%= f.collection_select :tournament_id, @parents,:id,:name,{},{class: 'tournament_select'} %> <%= f.label "高校選択" %> <%= f.collection_select :school_id, @parents.children,:id,:name,{},{class: 'tournament_select'} %> ここでエラー <%= f.label :image, class: "form-image" do %>
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。