Boolean Fields


#1

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/


#2

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
http://yakimaherald.com
509-577-7732
removed_email_address@domain.invalid


#3

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/