From d0cb4d7258c9241fcffda854d615c44586189838 Mon Sep 17 00:00:00 2001 From: CassioMarques Date: Mon, 10 Nov 2008 20:31:05 -0200 Subject: [PATCH] Added note about testing booleans to validates_presence_of --- .../guides/html/activerecord_validations_callbacks.html | 8 ++++++++ .../guides/source/activerecord_validations_callbacks.txt | 2 ++ 2 files changed, 10 insertions(+) diff --git a/railties/doc/guides/html/activerecord_validations_callbacks.html b/railties/doc/guides/html/activerecord_validations_callbacks.html index 2e5044eb6ece8..6953c3979a8da 100644 --- a/railties/doc/guides/html/activerecord_validations_callbacks.html +++ b/railties/doc/guides/html/activerecord_validations_callbacks.html @@ -567,6 +567,14 @@

3.10. The validates_presenc validates_presence_of :order_id end +
+ + + +
+Note +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
+

The default error message for validates_presence_of is "can't be empty".

3.11. The validates_size_of helper

3.12. The validates_uniqueness_of+ helper

diff --git a/railties/doc/guides/source/activerecord_validations_callbacks.txt b/railties/doc/guides/source/activerecord_validations_callbacks.txt index 568ab8bc23bb2..4dfa92e542606 100644 --- a/railties/doc/guides/source/activerecord_validations_callbacks.txt +++ b/railties/doc/guides/source/activerecord_validations_callbacks.txt @@ -256,6 +256,8 @@ class LineItem < ActiveRecord::Base end ------------------------------------------------------------------ +NOTE: 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 + The default error message for +validates_presence_of+ is "_can't be empty_". === The +validates_size_of+ helper