Nested form update action producing duplicate results

前端 未结 2 622
旧时难觅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
    
    0 讨论(0)
  • 2021-01-22 07:15

    Try adding update_only to your call to accepts_nested_attributes_for.

    accepts_nested_attributes_for :nested_attribute, update_only: true
    
    0 讨论(0)
提交回复
热议问题