Deep Nested Rails 4 Form

前端 未结 2 1791
名媛妹妹
名媛妹妹 2020-12-31 16:29

I have 3 models Item which accepts nested attributes for questions and questions accept nested attributes for answers. I\'m trying to create an item which has a question and

2条回答
  •  误落风尘
    2020-12-31 17:01

    I think your problem is with your strong params:

    def item_params
          params.require(:item).permit(:id, :content, :kind, questions_attributes: [:content, :helper_text, :kind, answers_attributes: [:content, :correct]])
    end   
    

    Basically, when you pass a deep nested form (where you have multiple dependent models), you'll have to pass the attributes as part of the other model's attributes. You had the params as separate

提交回复
热议问题