# How to populate a select list

**URL:** <https://www.ruby-forum.com/t/how-to-populate-a-select-list/72286>\
**Category:** Rails\
**Created:** [October 16, 2006, 7:53am UTC](https://www.ruby-forum.com/t/how-to-populate-a-select-list/72286 "2006-10-16T07:53:08Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![ldk2005](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/d9b06d/32.png) [@ldk2005](https://www.ruby-forum.com/u/ldk2005)\
**Post date:** [October 16, 2006, 7:53am UTC](https://www.ruby-forum.com/t/how-to-populate-a-select-list/72286/1 "2006-10-16T07:53:08Z")

</div>

I’m creating a simple ‘Yes/No’ select droplist. I thought the select  
tag accepted a hash. But, it doesn’t show any items when I view it.  
This is the code in Markaby 0.5.

select\_tag( ‘work\_order’, ‘warranty\_work\_ny’,{“Yes” =\> “Y”, “No” =\>  
“N”})

## There must be an obvious error in there somewhere, I’m just not seeing it.

Best Regards,  
-Larry  
“Work, work, work…there is no satisfactory alternative.”  
— E.Taft Benson

---

<div class="post-metadata">

**Author:** ![ldk2005](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/d9b06d/32.png) [@ldk2005](https://www.ruby-forum.com/u/ldk2005)\
**Post date:** [October 16, 2006, 8:07am UTC](https://www.ruby-forum.com/t/how-to-populate-a-select-list/72286/2 "2006-10-16T08:07:41Z")

</div>

Larry K. wrote:

> I’m creating a simple ‘Yes/No’ select droplist. I thought the select  
> tag accepted a hash. But, it doesn’t show any items when I view it.  
> This is the code in Markaby 0.5.
> 
> select\_tag( ‘work\_order’, ‘warranty\_work\_ny’,{“Yes” =\> “Y”, “No” =\>  
> “N”})
> 
> ## There must be an obvious error in there somewhere, I’m just not seeing it.
> 
> Best Regards,  
> -Larry  
> “Work, work, work…there is no satisfactory alternative.”  
> — E.Taft Benson

try

select\_tag(name, option\_tags = nil, options = {})  
but  
select(object, method, choices, options = {}, html\_options = {})  
try  
select\_tag( ‘warranty\_work\_ny’,{“Yes” =\> “Y”, “No” =\> “N”})

---

<div class="post-metadata">

**Author:** ![ldk2005](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/d9b06d/32.png) [@ldk2005](https://www.ruby-forum.com/u/ldk2005)\
**Post date:** [October 16, 2006, 2:17pm UTC](https://www.ruby-forum.com/t/how-to-populate-a-select-list/72286/3 "2006-10-16T14:17:01Z")

</div>

You want the select helper, not select\_tag, since you are tying it to  
your work\_order.warranty\_work\_ny method. This helper accepts an array of  
arrays for the choices, not a hash.

Here’s how you do it…

select(‘work\_order’, ‘warranty\_work\_ny’, [[“Yes”,“Y”],[“No”,“N”]])

c.

Larry K. wrote:

> I’m creating a simple ‘Yes/No’ select droplist. I thought the select  
> tag accepted a hash. But, it doesn’t show any items when I view it.  
> This is the code in Markaby 0.5.
> 
> select\_tag( ‘work\_order’, ‘warranty\_work\_ny’,{“Yes” =\> “Y”, “No” =\>  
> “N”})
> 
> ## There must be an obvious error in there somewhere, I’m just not seeing it.
> 
> Best Regards,  
> -Larry  
> “Work, work, work…there is no satisfactory alternative.”  
> — E.Taft Benson

---

<div class="post-metadata">

**Author:** ![ldk2005](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/d9b06d/32.png) [@ldk2005](https://www.ruby-forum.com/u/ldk2005)\
**Post date:** [October 16, 2006, 3:49pm UTC](https://www.ruby-forum.com/t/how-to-populate-a-select-list/72286/4 "2006-10-16T15:49:38Z")

</div>

On Oct 16, 1:44 am, “Larry K.” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> “Work, work, work…there is no satisfactory alternative.”  
> — E.Taft Benson

> From a user interface perspective, a ‘select’ for a yes/no question is  
> a bad idea.

For a boolean state object I suggest one of two approaches…

1. A checkbox or
2. two radio buttons.

In your case, it sounds like you really need to put in a checkbox

I use the radio button approach when the states match to a small set of  
mutually exclusive states that don’t neatly map to a true/false.  
Things like ‘gender’ are a good example.

\_Kevin

---

<div class="post-metadata">

**Author:** ![ldk2005](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/d9b06d/32.png) [@ldk2005](https://www.ruby-forum.com/u/ldk2005)\
**Post date:** [October 16, 2006, 5:12pm UTC](https://www.ruby-forum.com/t/how-to-populate-a-select-list/72286/5 "2006-10-16T17:12:18Z")

</div>

On 16 Oct 2006, at 14:48, \_Kevin wrote:

> On Oct 16, 1:44 am, “Larry K.” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> 
> > I’m creating a simple ‘Yes/No’ select droplist. I thought the select  
> > tag accepted a hash. But, it doesn’t show any items when I view it.  
> > This is the code in Markaby 0.5.
> > 
> > select\_tag( ‘work\_order’, ‘warranty\_work\_ny’,{“Yes” =\> “Y”, “No”  
> > =\> “N”})
> > 
> > There must be an obvious error in there somewhere, I’m just not  
> > seeing it.

select\_tag takes: name for params, options for popup, html options.  
So you have an extra argument slipped in there, and you should really  
use options\_for\_select to build the options string. try:

select\_tag(:warranty\_work\_ny, options\_for\_select({“Yes” =\> “Y”, “No”  
=\> “N”}))

(typed into mail, apologies in advance for the errors)

> From a user interface perspective, a ‘select’ for a yes/no question is  
> a bad idea.

From the survey design PoV, any binary (Yes/No) question has four  
possible and appropriate responses:

Yes;  
No;  
Don’t know;  
not applicable.

Plus also:

Not Answered.

> For a boolean state object I suggest one of two approaches…
> 
> 1. A checkbox or
> 2. two radio buttons.
> 
> In your case, it sounds like you really need to put in a checkbox
> 
> I use the radio button approach when the states match to a small  
> set of  
> mutually exclusive states that don’t neatly map to a true/false.  
> Things like ‘gender’ are a good example.

Most binary survey questions fall into the same camp. From the UI  
perspective, popups/dropdowns are biased towards the first option,  
the one that shows by default.

Paul
