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.
D9d1b31a337f46ac5e4dd56b55404f58?d=identicon&s=25 Dylan Markow (Guest)
on 2005-12-29 23:49
(Received via mailing list)
Rails mailing list
Fc2deb08e3fa573867b250dd6b71d1a6?d=identicon&s=25 Eifion Bedford (Guest)
on 2005-12-30 00: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 }  %>

132a94ca65959bda6c74fae54bff2425?d=identicon&s=25 Ezra Zygmuntowicz (Guest)
on 2005-12-30 00:05
(Received via mailing list)
On Dec 29, 2005, at 2:46 PM, Dylan Markow wrote:

> Rails mailing list


	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 Zygmuntowicz
Yakima Herald-Republic
This topic is locked and can not be replied to.