I think options_for_select is backwards


#1

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
http://mail.yahoo.com


#2

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