# Validates\_presence\_of fails with false boolean

**URL:** <https://www.ruby-forum.com/t/validates-presence-of-fails-with-false-boolean/157542>\
**Category:** Rails\
**Created:** [January 12, 2009, 11:53pm UTC](https://www.ruby-forum.com/t/validates-presence-of-fails-with-false-boolean/157542 "2009-01-12T23:53:03Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![taylorstrait](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/b5a626/32.png) [@taylorstrait](https://www.ruby-forum.com/u/taylorstrait)\
**Post date:** [January 12, 2009, 11:53pm UTC](https://www.ruby-forum.com/t/validates-presence-of-fails-with-false-boolean/157542/1 "2009-01-12T23:53:03Z")

</div>

This almost feels like a bug to me, since false is not nil. (i don’t  
think!) Using v\_p\_o on a boolean field fails validation if the field is  
passed with ‘false’. It passes validation in the case of true. How can  
I validate \_presence\_of a boolean if it is submitted false?

---

<div class="post-metadata">

**Author:** ![taylorstrait](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/b5a626/32.png) [@taylorstrait](https://www.ruby-forum.com/u/taylorstrait)\
**Post date:** [January 13, 2009, 12:18am UTC](https://www.ruby-forum.com/t/validates-presence-of-fails-with-false-boolean/157542/2 "2009-01-13T00:18:16Z")

</div>

You should use validates\_inclusion\_of. See:

[http://www.railsbrain.com/api/rails-2.2.2/doc/index.html?a=M001821&name=validates\_presence\_of](http://www.railsbrain.com/api/rails-2.2.2/doc/index.html?a=M001821&name=validates_presence_of)

Regards,  
Craig

On Mon, Jan 12, 2009 at 5:53 PM, Taylor S. \<

---

<div class="post-metadata">

**Author:** ![taylorstrait](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/b5a626/32.png) [@taylorstrait](https://www.ruby-forum.com/u/taylorstrait)\
**Post date:** [January 13, 2009, 12:24am UTC](https://www.ruby-forum.com/t/validates-presence-of-fails-with-false-boolean/157542/3 "2009-01-13T00:24:46Z")

</div>

Craig D. wrote:

> You should use validates\_inclusion\_of. See:
> 
> [http://www.railsbrain.com/api/rails-2.2.2/doc/index.html?a=M001821&name=validates\_presence\_of](http://www.railsbrain.com/api/rails-2.2.2/doc/index.html?a=M001821&name=validates_presence_of)
> 
> Regards,  
> Craig
> 
> On Mon, Jan 12, 2009 at 5:53 PM, Taylor S. \<

Doh. I searched google and ruby-forum, but who would have thought to  
look in the API docs:

“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”

Thanks.
