Forum: Ruby on Rails options_for_select order

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Dylan M. (Guest)
on 2005-12-30 00:49
(Received via mailing list)
_______________________________________________
Rails mailing list
removed_email_address@domain.invalid
http://lists.rubyonrails.org/mailman/listinfo/rails
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 }  %>



Eifion
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
> 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
This topic is locked and can not be replied to.