You specified
required: false
, in Rails > 5.0 the required option is deprecated and you want to use optional: true
.25end
26
27class Post < ApplicationRecord
28 belongs_to :blog, required: false29end
Description
Since Rails 5, belongs_to
associations are required by default and this can be controlled through the use of optional: true
.
Bad practice
class Post < ApplicationRecord
belongs_to :blog, required: false
end
class Post < ApplicationRecord
belongs_to :blog, required: true
end
Recommended
class Post < ApplicationRecord
belongs_to :blog, optional: true
end
class Post < ApplicationRecord
belongs_to :blog, optional: false
end