How to sort select tag options?


#1

Hi,
I have a select tag as :
<%= select(:feedbacks, :directedto , {"----Select
One----"=>“none”,“Business contact”=>“Business Contact”,“Technical
support”=>“Technical Support”,“Payment Help”=>“Payment Help”},{
:selected => “none”},
{:class=>“field”, :style=>“width:192px;”}) %>

I want the select options in the drop down to appear in the same order
as I have written them in the code…
But…this does not happen…and the options appear in any random
order…!!!
Can anyone please help me…as to how should I sort my select options…
Thank you…


#2

problem is that you are using a hash, which have no guaranteed order.
try an array like this:

<%= select(:feedbacks, :directedto, ([["----Select One----",
“none”], [“Business contact”, “Business Contact”], [“Technical
support”, “Technical Support”], [“Payment Help”, “Payment Help”]]),
{:selected => “none”}, {:class=>“field”, :style=>“width:192px;”}) %>


#3

MaD wrote:

problem is that you are using a hash, which have no guaranteed order.
try an array like this:

<%= select(:feedbacks, :directedto, ([["----Select One----",
“none”], [“Business contact”, “Business Contact”], [“Technical
support”, “Technical Support”], [“Payment Help”, “Payment Help”]]),
{:selected => “none”}, {:class=>“field”, :style=>“width:192px;”}) %>

Thank You so much…
That did the trick…
Thanks again…