With a hash such as:
stuff = {''1''=>''desc 1'',
''2''=>''desc 2'',
''3''=>''desc 3''}
options_for_select(stuff) will output:
<option id="desc 1">1</option>
<option id="desc 2">2</option>
<option id="desc 3">3</option>
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
--- CSN <cool_screen_name90001@yahoo.com> wrote:> BTW, is there a simple way to swap a hash''s keys and > values (keys become values and vice versa). Probably > with .each ?Ah, .invert does the trick! __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com
CSN wrote:> With a hash such as: > > stuff = {''1''=>''desc 1'', ''2''=>''desc 2'', ''3''=>''desc 3''} > > options_for_select(stuff) will output: > > <option id="desc 1">1</option> > <option id="desc 2">2</option> > <option id="desc 3">3</option> >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 -- Posted via http://www.ruby-forum.com/.