# Boolean db fields set to false fail validation with validate

**URL:** <https://www.ruby-forum.com/t/boolean-db-fields-set-to-false-fail-validation-with-validate/86942>\
**Category:** Rails\
**Created:** [February 27, 2007, 12:44am UTC](https://www.ruby-forum.com/t/boolean-db-fields-set-to-false-fail-validation-with-validate/86942 "2007-02-27T00:44:33Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![scott](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/3e96dc/32.png) [@scott](https://www.ruby-forum.com/u/scott)\
**Post date:** [February 27, 2007, 12:44am UTC](https://www.ruby-forum.com/t/boolean-db-fields-set-to-false-fail-validation-with-validate/86942/1 "2007-02-27T00:44:33Z")

</div>

I have a model that contains a :boolean field. In my view, I have a  
simple select of Yes or No, which equates to true or false,  
respectively. If I choose yes and save, everything works great. If I  
choose no, my model fails validation as I have this set as a required  
field using validates\_presence\_of. I have checked the log and it’s  
definitely set to false, why would this fail validation?

Thanks,

Scott

---

<div class="post-metadata">

**Author:** ![scott](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/3e96dc/32.png) [@scott](https://www.ruby-forum.com/u/scott)\
**Post date:** [February 27, 2007, 3:10pm UTC](https://www.ruby-forum.com/t/boolean-db-fields-set-to-false-fail-validation-with-validate/86942/2 "2007-02-27T15:10:56Z")

</div>

Anyone else seeing this? If not, would someone mind sending me a  
snippet of a view/model that used a boolean that doesn’t suffer from  
this?

Thanks,

Scott

---

<div class="post-metadata">

**Author:** ![scott](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/3e96dc/32.png) [@scott](https://www.ruby-forum.com/u/scott)\
**Post date:** [February 27, 2007, 4:24pm UTC](https://www.ruby-forum.com/t/boolean-db-fields-set-to-false-fail-validation-with-validate/86942/3 "2007-02-27T16:24:10Z")

</div>

See  
[http://api.rubyonrails.org/classes/ActiveRecord/Validations/ClassMethods.html#M000941](http://api.rubyonrails.org/classes/ActiveRecord/Validations/ClassMethods.html#M000941)

It basically says that due to some other bits of AR magic, you have to  
validate\_presence\_of kind of funky on boolean variables:  
validates\_inclusion\_of :field\_name, :in =\> [true, false]
