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
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