Rails nested form error, child must exist

前端 未结 1 617
余生分开走
余生分开走 2021-01-18 02:13

I\'m following the tutorial: http://www.amooma.de/screencasts/2015-01-22-nested_forms-rails-4.2/

I\'m usign Rails 5.0.0.1

But when I register a hotel, it a

相关标签:
1条回答
  • 2021-01-18 02:42

    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 optional: true while declaring belongs_to in your Category model as follows:

    class Category < ApplicationRecord
      belongs_to :hotel, optional: true
      validates :name, presence: true
    end 
    
    0 讨论(0)
提交回复
热议问题