# ActiveRecord validates\_presence\_of with false

**URL:** <https://www.ruby-forum.com/t/activerecord-validates-presence-of-with-false/110621>\
**Category:** Rails\
**Created:** [July 28, 2007, 8:42am UTC](https://www.ruby-forum.com/t/activerecord-validates-presence-of-with-false/110621 "2007-07-28T08:42:44Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Hendy\_I](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/b4bc9f/32.png) [@Hendy\_I](https://www.ruby-forum.com/u/Hendy_I)\
**Post date:** [July 28, 2007, 8:42am UTC](https://www.ruby-forum.com/t/activerecord-validates-presence-of-with-false/110621/1 "2007-07-28T08:42:44Z")

</div>

Hi Rails

I can’t seem to use a boolean value ‘false’ with validates\_presence\_of.  
It always fails.

I even tried using ‘f’.

What’s the proper way to set a false value?

Isn’t false a “present” value in a boolean column?

What I want is to require either true or false, but prevent nil 🙂

Thank you

–  
Hendy I.

> **[Hendy Irawan | Social Enterprise Consulting](https://www.hendyirawan.com)**
>
> Oxygen aid for COVID-19 patients in IndonesiaDistributing rice to the poor in IndonesiaDistributing aid to poor people in IndonesiaDistributing aid to poor people in Indonesia Donate to Indonesia Why

---

<div class="post-metadata">

**Author:** ![Hendy\_I](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/b4bc9f/32.png) [@Hendy\_I](https://www.ruby-forum.com/u/Hendy_I)\
**Post date:** [July 28, 2007, 5:20pm UTC](https://www.ruby-forum.com/t/activerecord-validates-presence-of-with-false/110621/2 "2007-07-28T17:20:25Z")

</div>

Hendy I. wrote:

> What I want is to require either true or false, but prevent nil 🙂

From the API docs for validates\_presence\_of:

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

This should do the trick!

* * *

Ryan Carmelo Briones

–  
View this message in context:  
[http://www.nabble.com/ActiveRecord-validates\_presence\_of-with-false-tf4161367.html#a11843712](http://www.nabble.com/ActiveRecord-validates_presence_of-with-false-tf4161367.html#a11843712)  
Sent from the RubyOnRails Users mailing list archive at [Nabble.com](http://Nabble.com).
