Rails Nested Forms Not Updating Nested Model

这一生的挚爱 提交于 2019-12-06 07:07:17

When you are creating a new record you don't need its id to be permitted as it's not been created but when you want to update your record you need to pass id to the permitted attributes, else it will work with create but not when you want to update your record, so you need to do:

def trip_params
  params.require(:trip).permit(:id, :name, :start_date, :end_date,  segments_attributes: [:id,:start_location_id,:end_location_id, :date])
end
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!