ruby on rails - How to make a model's column optional in rails5 - Stack Overflow

PHOTO EMBED

Thu Aug 20 2020 01:16:40 GMT+0000 (UTC)

Saved by @ludaley #rb #rubyonrails

When you want an optional belongs_to:


1) Just don't add in the field's migration
#migration_file_name.rb
#PLEASE DO NOT DO
null: false 

2) In the model use
#PLEASE DO
belongs_to :community, optional: true
content_copyCOPY

https://stackoverflow.com/questions/46053658/how-to-make-a-models-column-optional-in-rails5