Options_for_select order


#1

Rails mailing list
removed_email_address@domain.invalid
http://lists.rubyonrails.org/mailman/listinfo/rails


#2

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 } %>

Eifion


#3

On Dec 29, 2005, at 2:46 PM, Dylan M. wrote:

Rails mailing list
removed_email_address@domain.invalid
http://lists.rubyonrails.org/mailman/listinfo/rails

Dylan-

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”] ] %>

Cheers-
-Ezra Z.
Yakima Herald-Republic
WebMaster
http://yakimaherald.com
509-577-7732
removed_email_address@domain.invalid