Nested form update action producing duplicate results

前端 未结 2 640
旧时难觅i
旧时难觅i 2021-01-22 06:20

During the update action of a nested form, instead of updating the current nested records, it seems to create new nested records.

This is what my controller looks like

2条回答
  •  独厮守ぢ
    2021-01-22 07:03

    update_only does not work for has_many relationships. You need to add the nested attribute :id field to your strong parameters:

    def application_params
       params.require(:application).permit(:job_id, :user_id, 
         answers_attributes:[:id, :question_id, :content]).merge(user_id: current_user.id,
         job_id: params[:job_id])
    end
    

提交回复
热议问题