Rails nested form error, child must exist

风流意气都作罢 提交于 2019-12-01 17:30:58

belongs_to behavior has changed in rails >= 5.x. Essentially it is now expected that the belongs_to record exists before assigning it to the other side of the association. You need to pass required :false while declaring belongs_to in your Category model as follows:

class Category < ApplicationRecord
  belongs_to :hotel, required: false
  validates :name, presence: true
end 
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!