Skip to content
Browse files

Document validates_presences_of behavior with booleans: you probably …

…want validates_inclusion_of :attr, :in => [true, false]. Closes #2253.

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@4980 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
1 parent 9f3ba03 commit f3d6726dfa3efdb895a85f5e2f72e7b430b788e9 @jeremy jeremy committed
Showing with 6 additions and 0 deletions.
  1. +2 −0 activerecord/CHANGELOG
  2. +4 −0 activerecord/lib/active_record/validations.rb
View
2 activerecord/CHANGELOG
@@ -1,5 +1,7 @@
*SVN*
+* Document validates_presences_of behavior with booleans: you probably want validates_inclusion_of :attr, :in => [true, false]. #2253 [Bob Silva]
+
* Optimistic locking: gracefully handle nil versions, treat as zero. #5908 [Tom Ward]
* validates_confirmation_of only kicks in when the attribute, rather than its confirmation, is present. #785 [z@wzph.com]
View
4 activerecord/lib/active_record/validations.rb
@@ -375,6 +375,10 @@ def validates_acceptance_of(*attr_names)
#
# The first_name attribute must be in the object and it cannot be blank.
#
+ # If you want to validate the presence of a boolean field (where the real values are true and false),
+ # you will want to use validates_inclusion_of :field_name, :in => [true, false]
+ # This is due to the way Object#blank? handles boolean values. false.blank? # => true
+ #
# Configuration options:
# * <tt>message</tt> - A custom error message (default is: "can't be blank")
# * <tt>on</tt> - Specifies when this validation is active (default is :save, other options :create, :update)

0 comments on commit f3d6726

Please sign in to comment.
Something went wrong with that request. Please try again.