# Boolean Fields

**URL:** <https://www.ruby-forum.com/t/boolean-fields/96019>\
**Category:** Rails\
**Created:** [November 15, 2005, 7:00am UTC](https://www.ruby-forum.com/t/boolean-fields/96019 "2005-11-15T07:00:38Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![dave](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/ee7513/32.png) [@dave](https://www.ruby-forum.com/u/dave)\
**Post date:** [November 15, 2005, 7:00am UTC](https://www.ruby-forum.com/t/boolean-fields/96019/1 "2005-11-15T07:00:38Z")

</div>

Does anyone have experience with using boolean fields (Postgres here,  
but I  
assume it’s the same on MySQL)? Is there any reason the scaffold  
generator  
explicitly writes out the whole tags rather than use select helpers? It  
has  
a default value specified that does not reflect the DB (always false).  
The  
code is also not XHTML compliant (selected is just selected, not  
selected=“selected”, which seems strange, since as far as I can tell,  
usual  
generated Rails code seems to be nice and XHTML compliant).

I made my own little true / false option select helper, but it doesn’t  
reflect  
the database either.

The code was literally cut and pasted from another bit of my app where I  
use  
the same technique to have a select list of options, and that time it  
does  
represent the database perfectly (it’s basically like some kind of enum  
list,  
which this little true/false selector is too).

## But my boolean select thing won’t reflect the database, even though it does a perfect job of altering the values when I change them. Here’s the code

it’s ridiculously simple, so I have no idea why it’s not working as I  
hoped:

def boolean\_select(object, fieldname, options ={})  
select(object, fieldname, {“True” =\> “true”, “False” =\> “false”},  
options)  
end

I also previously tried:

def boolean\_select(object, fieldname, options ={})  
select(object, fieldname, %w{true false}, options)  
end

It doesn’t work, and I’m puzzled by it!

Best regards,

~Dave

–

Dave S.  
Rent-A-Monkey Website Development  
Web: [http://www.rentamonkey.com/](http://www.rentamonkey.com/)

---

<div class="post-metadata">

**Author:** ![dave](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/ee7513/32.png) [@dave](https://www.ruby-forum.com/u/dave)\
**Post date:** [November 15, 2005, 5:36pm UTC](https://www.ruby-forum.com/t/boolean-fields/96019/2 "2005-11-15T17:36:21Z")

</div>

On Nov 14, 2005, at 9:57 PM, Dave S. wrote:

> tell, usual  
> represent the database perfectly (it’s basically like some kind of  
> def boolean\_select(object, fieldname, options ={})  
> It doesn’t work, and I’m puzzled by it!
> 
> Best regards,
> 
> ~Dave

Hey Dave-

```
As far as i can tell you need to use true and false without the

```

quotes. Having the quotes around them effectively turn them into  
strings and not ruby TrueClass and FalseClass. So just remove that  
and try again. Other than that I think it should work fine.

Cheers-  
-Ezra Z.  
Yakima Herald-Republic  
WebMaster

> **[yakimaherald.com | Yakima, Washington - We Tell Your Stories](https://www.yakimaherald.com/)**

509-577-7732  
removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![dave](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/ee7513/32.png) [@dave](https://www.ruby-forum.com/u/dave)\
**Post date:** [November 18, 2005, 2:20pm UTC](https://www.ruby-forum.com/t/boolean-fields/96019/3 "2005-11-18T14:20:52Z")

</div>

On Tuesday 15 Nov 2005 16:29, Ezra Z. wrote:

> As far as i can tell you need to use true and false without the  
> quotes. Having the quotes around them effectively turn them into  
> strings and not ruby TrueClass and FalseClass. So just remove that  
> and try again. Other than that I think it should work fine.

Thanks Ezra, the following works perfectly:

def boolean\_select(object, fieldname, options ={})  
select(object, fieldname, {“True” =\> true, “False” =\> false}, options)  
end

Cheers,

~Dave

–

Dave S.  
Rent-A-Monkey Website Development  
Web: [http://www.rentamonkey.com/](http://www.rentamonkey.com/)
