# Another select\_list question - bad bad booleans

**URL:** <https://www.ruby-forum.com/t/another-select-list-question-bad-bad-booleans/75112>\
**Category:** Rails\
**Created:** [March 1, 2006, 7:36am UTC](https://www.ruby-forum.com/t/another-select-list-question-bad-bad-booleans/75112 "2006-03-01T07:36:48Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![craigrails](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/c2a13f/32.png) [@craigrails](https://www.ruby-forum.com/u/craigrails)\
**Post date:** [March 1, 2006, 7:36am UTC](https://www.ruby-forum.com/t/another-select-list-question-bad-bad-booleans/75112/1 "2006-03-01T07:36:48Z")

</div>

I have a select list for a boolean column in postgresql

in the ‘model’ …  
YES\_NO = [  
[“Yes”, “1”],  
[“No”, “0”]  
].freeze

in the ‘view code’ …

\<%= options = [[‘Accepted?’, ‘’]] + Placement::YES\_NO  
select(“placement”, “accepted”, options) %\>

When creating new records, I can select Yes or No and it writes the  
proper value to table.

When I edit existing records, unlike other select list menus which  
automatically go to the existing value in the select list, the  
‘Accepted’ list always displays "Accepted?’ (the prompt, never the  
value) in the pop-up selected list, no doubt because it cannot figure  
out the reverse translation of existing column 0’s and 1’s backwards to  
Yes : No logic.

What is the trick to do that?

Thanks

Craig

---

<div class="post-metadata">

**Author:** ![craigrails](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/c2a13f/32.png) [@craigrails](https://www.ruby-forum.com/u/craigrails)\
**Post date:** [March 1, 2006, 8:35am UTC](https://www.ruby-forum.com/t/another-select-list-question-bad-bad-booleans/75112/2 "2006-03-01T08:35:27Z")

</div>

I know this doesn’t answer your question… it’s late here, but why are  
you using a drop down for a binary choice instead of something like a  
check box or radio button?

\_Kevin

---

<div class="post-metadata">

**Author:** ![craigrails](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/c2a13f/32.png) [@craigrails](https://www.ruby-forum.com/u/craigrails)\
**Post date:** [March 2, 2006, 2:42am UTC](https://www.ruby-forum.com/t/another-select-list-question-bad-bad-booleans/75112/3 "2006-03-02T02:42:26Z")

</div>

using radio buttons for a boolean defies logic as I can’t make sense of  
the api

radio\_button\_tag(name, value, checked = false, options = {})

from my example below…

\<%= radio\_button\_tag(‘placement’, ‘accepted’ ‘?’ %\>

field is to have either 0 or 1 - display should be “Yes” or “No”

The pop-up list for Yes or No works fine except that in edit mode, the  
value already exists in the column and all I really need is for it to  
preselect “Yes” or “No” based upon the column contents. The above radio  
button api (with absolutely no examples) doesn’t make a lick of sense to  
me.

Craig

---

<div class="post-metadata">

**Author:** ![craigrails](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/c2a13f/32.png) [@craigrails](https://www.ruby-forum.com/u/craigrails)\
**Post date:** [March 1, 2006, 8:41am UTC](https://www.ruby-forum.com/t/another-select-list-question-bad-bad-booleans/75112/4 "2006-03-01T08:41:51Z")

</div>

Probably because I understood drop down boxes (at least until this  
issue) and hadn’t bothered to do any checkboxes/radio buttons yet. - No  
reason that I can’t change my bad habits I guess.

It does sort of make sense to use a radio button since either is  
required and I suppose I can default it one way for ‘new’ records.

Hmm…radio buttons…

Probably too late to tackle tonight as I am pretty much fried but even  
with radio buttons, I will have to reverse the binary logic of stored  
boolean back to common Yes/No vernacular.

Thanks

Craig

---

<div class="post-metadata">

**Author:** ![craigrails](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/c2a13f/32.png) [@craigrails](https://www.ruby-forum.com/u/craigrails)\
**Post date:** [March 2, 2006, 3:04am UTC](https://www.ruby-forum.com/t/another-select-list-question-bad-bad-booleans/75112/5 "2006-03-02T03:04:04Z")

</div>

Solved - never mind.

Good lesson learned and anyone else using booleans in postgres

0 and 1 are not what rails derives from tables…TRUE FALSE is what  
rails obtains from tables.

Craig
