Forum: Ruby on Rails options_for_select order

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Dylan M. (Guest)
on 2005-12-30 00:49
(Received via mailing list)
Rails mailing list
Eifion Bedford (Guest)
on 2005-12-30 01:01
(Received via mailing list)
I had this problem too. Your values are stored in a hash and hashes
don't keep their values in the order you added them. As you're
putting the same text it the value of each option as will appear in
the drop down list you could do this instead:

<%= select 'project', 'status', %w{ Active MD HOLD Dead }  %>

Ezra Z. (Guest)
on 2005-12-30 01:05
(Received via mailing list)
On Dec 29, 2005, at 2:46 PM, Dylan M. wrote:

> Rails mailing list
> removed_email_address@domain.invalid


	In ruby hashes never gauranteed order. They are essentially randomly
ordered. So you will either need to use a .sort method on them if you
wanted them in alphabetical order or you will need to feed in a
nested array instead like so:

<%= select 'project', 'status', [["Active" ,"Active"], ["MD", "MD"],
["HOLD" , "HOLD"], ["Dead", "Dead"] ]  %>

-Ezra Z.
Yakima Herald-Republic
This topic is locked and can not be replied to.