# Check whether the boolean value true or false

**URL:** <https://www.ruby-forum.com/t/check-whether-the-boolean-value-true-or-false/152281>\
**Category:** Rails\
**Created:** [November 1, 2008, 6:59am UTC](https://www.ruby-forum.com/t/check-whether-the-boolean-value-true-or-false/152281 "2008-11-01T06:59:21Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ishara\_G](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/e68b1a/32.png) [@Ishara\_G](https://www.ruby-forum.com/u/Ishara_G)\
**Post date:** [November 1, 2008, 6:59am UTC](https://www.ruby-forum.com/t/check-whether-the-boolean-value-true-or-false/152281/1 "2008-11-01T06:59:21Z")

</div>

i have a table called “confirm\_clients”,there are 3columns,they are  
t.column :user\_id, :string  
t.column :msg\_id, :string  
t.column :confirm, :boolean

i want to check whether the boolean value of confirm is true  
when a given user\_id and msg\_id,plz can anyone how can i do it

---

<div class="post-metadata">

**Author:** ![Ishara\_G](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/e68b1a/32.png) [@Ishara\_G](https://www.ruby-forum.com/u/Ishara_G)\
**Post date:** [November 1, 2008, 8:48am UTC](https://www.ruby-forum.com/t/check-whether-the-boolean-value-true-or-false/152281/2 "2008-11-01T08:48:15Z")

</div>

Ishara G. wrote:

> i have a table called “confirm\_clients”,there are 3columns,they are  
> t.column :user\_id, :string  
> t.column :msg\_id, :string  
> t.column :confirm, :boolean
> 
> i want to check whether the boolean value of confirm is true  
> when a given user\_id and msg\_id,plz can anyone how can i do it

try to use “before\_save” in model class

---

<div class="post-metadata">

**Author:** ![Ishara\_G](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/e68b1a/32.png) [@Ishara\_G](https://www.ruby-forum.com/u/Ishara_G)\
**Post date:** [November 1, 2008, 8:55am UTC](https://www.ruby-forum.com/t/check-whether-the-boolean-value-true-or-false/152281/3 "2008-11-01T08:55:41Z")

</div>

assuming 0 as false and 1 as true. Try it out  
confirm\_client=ConfirmClient.find(5) # I am supposing the client with  
id 5  
if confirm\_client.confirm==1 #yes indeed this client is verified  
do\_something  
else #not verified client  
do\_something\_else probably redirect to some place with  
flash[:notice]  
end

On Nov 1, 10:58 am, “Ishara G.” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![Ishara\_G](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/e68b1a/32.png) [@Ishara\_G](https://www.ruby-forum.com/u/Ishara_G)\
**Post date:** [November 1, 2008, 1:53pm UTC](https://www.ruby-forum.com/t/check-whether-the-boolean-value-true-or-false/152281/4 "2008-11-01T13:53:07Z")

</div>

On Nov 1, 7:54 am, mrbless [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> assuming 0 as false and 1 as true. Try it out  
> confirm\_client=ConfirmClient.find(5) # I am supposing the client with  
> id 5

How true/false are represented in the DB is database dependant. You  
don’t need to worry about that though - confirm\_client.confirm is  
typecasted by rails to either true or false no matter what the  
underlying column stores (t/f, 0/1, Y/N etc…)

Fred

---

<div class="post-metadata">

**Author:** ![Ishara\_G](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/e68b1a/32.png) [@Ishara\_G](https://www.ruby-forum.com/u/Ishara_G)\
**Post date:** [November 1, 2008, 6:56pm UTC](https://www.ruby-forum.com/t/check-whether-the-boolean-value-true-or-false/152281/5 "2008-11-01T18:56:31Z")

</div>

On Nov 1, 2008, at 8:52 AM, Frederick C. wrote:

> Fred  
> But, I’ve found that you almost always want to replace:  
> t.column :confirm, :boolean  
> with  
> t.column :confirm, :boolean, :default =\> false, :null =\> false

Unless you need the SQL NULL to mean something other than “not  
true” (because it is also “not false”)

Otherwise, something like:

ConfirmClient.find(:all, :conditions =\> { :confirm =\> [true,  
false] })

Does _NOT_ find all the records. This is usually when you begin to  
question your sanity until discovering the NULL values in the  
‘confirm’ column.

-Rob

Rob B. [http://agileconsultingllc.com](http://agileconsultingllc.com)  
removed\_email\_address@domain.invalid
