Rails 5 changed belongs_to default validation
New Rails 5 applications comes with this initializer:
# config/initializers/active_record_belongs_to_required_by_default.rb
Rails.application.config.active_record.belongs_to_required_by_default = true
So now, belongs_to
associations require presence by default.
In order to make this relation optional you can change the initializer value for the whole app, or add optional: true
to your relation:
belongs_to :user, optional: true
That's the code change.
Tweet