diff options
author | Zachary Scott <e@zzak.io> | 2014-10-03 17:36:56 -0700 |
---|---|---|
committer | Zachary Scott <e@zzak.io> | 2014-10-03 17:37:49 -0700 |
commit | a4d8b62ed19a0985a8f8cf8e7efe09263763f707 (patch) | |
tree | 6bb9e5c820388a3d384759809bd2b2647bc856cb /guides | |
parent | 44e6d91a07c26cfd7d7b5360cc9a8184b0692859 (diff) | |
download | rails-a4d8b62ed19a0985a8f8cf8e7efe09263763f707.tar.gz rails-a4d8b62ed19a0985a8f8cf8e7efe09263763f707.tar.bz2 rails-a4d8b62ed19a0985a8f8cf8e7efe09263763f707.zip |
Clarify possible validations you can use to avoid a NULL boolean value
in the database. Closes #16304 [ci skip]
Diffstat (limited to 'guides')
-rw-r--r-- | guides/source/active_record_validations.md | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/guides/source/active_record_validations.md b/guides/source/active_record_validations.md index 582bb240dd..4dc7203ba3 100644 --- a/guides/source/active_record_validations.md +++ b/guides/source/active_record_validations.md @@ -524,9 +524,15 @@ If you validate the presence of an object associated via a `has_one` or `marked_for_destruction?`. Since `false.blank?` is true, if you want to validate the presence of a boolean -field you should use `validates :field_name, inclusion: { in: [true, false] }`. +field you should use one of the following validations: -The default error message is _"can't be blank"_. +```ruby +validates :boolean_field_name, presence: true +validates :boolean_field_name, inclusion: { in: [true, false] } +validates :boolean_field_name, exclusion: { in: [nil] } +``` +By using one of these validations, you will ensure the value will NOT be `nil` +which would result in a `NULL` value in most cases. ### `absence` |