I''m trying to create a Select box using the following code: <%= select ''project'', ''status'', { "Active" => "Active", "MD" => "MD", "HOLD" => "HOLD", "Dead" => "Dead" } %> You''d think the select box would keep them in that order. However, the displayed page has them in a seemingly random order instead (MD, Active, Dead, Hold). No matter what order I enter them in, they always come out in this same "random" order. Thanks! _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
On Dec 29, 2005, at 2:46 PM, Dylan Markow wrote:> I''m trying to create a Select box using the following code: > > <%= select ''project'', ''status'', { "Active" => "Active", "MD" => > "MD", "HOLD" => "HOLD", "Dead" => "Dead" } %> > > You''d think the select box would keep them in that order. However, > the displayed page has them in a seemingly random order instead > (MD, Active, Dead, Hold). No matter what order I enter them in, > they always come out in this same "random" order. Thanks! > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/railsDylan- 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 Zygmuntowicz Yakima Herald-Republic WebMaster http://yakimaherald.com 509-577-7732 ezra-gdxLOakOTQ9oetBuM9ipNAC/G2K4zDHf@public.gmane.org
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 On 29 Rhag 2005, at 22:46, Dylan Markow wrote:> I''m trying to create a Select box using the following code: > > <%= select ''project'', ''status'', { "Active" => "Active", "MD" => > "MD", "HOLD" => "HOLD", "Dead" => "Dead" } %> > > You''d think the select box would keep them in that order. However, > the displayed page has them in a seemingly random order instead > (MD, Active, Dead, Hold). No matter what order I enter them in, > they always come out in this same "random" order. Thanks! > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails_______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails