Skip to content
Browse files

Added note about testing booleans to validates_presence_of

  • Loading branch information...
1 parent 0668ab6 commit d0cb4d7258c9241fcffda854d615c44586189838 @cassiomarques cassiomarques committed
View
8 railties/doc/guides/html/activerecord_validations_callbacks.html
@@ -567,6 +567,14 @@ <h3 id="_the_tt_validates_presence_of_tt_helper">3.10. The <tt>validates_presenc
validates_presence_of <span style="color: #990000">:</span>order_id
<span style="font-weight: bold"><span style="color: #0000FF">end</span></span>
</tt></pre></div></div>
+<div class="admonitionblock">
+<table><tr>
+<td class="icon">
+<img src="./images/icons/note.png" alt="Note" />
+</td>
+<td class="content">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 &#8658; [true, false] This is due to the way Object#blank? handles boolean values. false.blank? # &#8658; true</td>
+</tr></table>
+</div>
<div class="para"><p>The default error message for <tt>validates_presence_of</tt> is "<em>can't be empty</em>".</p></div>
<h3 id="_the_tt_validates_size_of_tt_helper">3.11. The <tt>validates_size_of</tt> helper</h3>
<h3 id="_the_validates_uniqueness_of_helper">3.12. The validates_uniqueness_of+ helper</h3>
View
2 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

0 comments on commit d0cb4d7

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