# I think options\_for\_select is backwards

**URL:** <https://www.ruby-forum.com/t/i-think-options-for-select-is-backwards/52447>\
**Category:** Rails\
**Created:** [January 14, 2006, 9:21am UTC](https://www.ruby-forum.com/t/i-think-options-for-select-is-backwards/52447 "2006-01-14T09:21:53Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![csn](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/db5fbb/32.png) [@csn](https://www.ruby-forum.com/u/csn)\
**Post date:** [January 14, 2006, 9:21am UTC](https://www.ruby-forum.com/t/i-think-options-for-select-is-backwards/52447/1 "2006-01-14T09:21:53Z")

</div>

With a hash such as:

stuff = {‘1’=\>‘desc 1’, ‘2’=\>‘desc 2’, ‘3’=\>‘desc 3’}

options\_for\_select(stuff) will output:

1 2 3

Doesn’t this seem backwards? Hash keys correspond to  
ids, and should be used for option ids IMO.

BTW, is there a simple way to swap a hash’s keys and  
values (keys become values and vice versa). Probably  
with .each ?

csn

* * *

Do You Yahoo!?  
Tired of spam? Yahoo! Mail has the best spam protection around

> **[Yahoo Mail - Organized Email](https://mail.yahoo.com)**
>
> It's time to get stuff done with Yahoo Mail. Just add your Gmail, Outlook, AOL or Yahoo Mail to get going. We automatically organize all the things life throws at you, like receipts and attachments, so you can find what you need fast. Plus, we've got...

---

<div class="post-metadata">

**Author:** ![csn](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/db5fbb/32.png) [@csn](https://www.ruby-forum.com/u/csn)\
**Post date:** [January 14, 2006, 12:56pm UTC](https://www.ruby-forum.com/t/i-think-options-for-select-is-backwards/52447/2 "2006-01-14T12:56:54Z")

</div>

CSN wrote:

> With a hash such as:
> 
> stuff = {‘1’=\>‘desc 1’, ‘2’=\>‘desc 2’, ‘3’=\>‘desc 3’}
> 
> options\_for\_select(stuff) will output:
> 
> 1 2 3

As a general rule, I would use an array to fill the options rather than  
a hash. Hashes are not guaranteed to return their contents in any  
particular order so you might end up with your options in a seemingly  
random order. Arrays will not do that.

[[“desc 1”, “1”],[“desc 2”, “2”],[“desc 3”, “3”]]

\_Kevin
