Order Values in a Select Box Using select

Been trawling for a while and know there must be an easy answer to
this so reluctant to work round it.

My select box:

<%= form.select( :data, { “Yes” => “1”, “No” => “0”},{:prompt => “–
Select –”}) %>

The problem is the data is ordered alphabetically so the drop down
gives the options no, yes:

– Select – No Yes

instead of:

– Select – Yes No

Any thoughts?

Many thanks,

Mike

<%= f.select( :data, { “Yes” => “1”, “No” => “0”}.sort.reverse,
{:prompt => “–
Select –”}) %>

mikej wrote:

Been trawling for a while and know there must be an easy answer to
this so reluctant to work round it.

My select box:

<%= form.select( :data, { “Yes” => “1”, “No” => “0”},{:prompt => “�
Select �”}) %>

The problem is the data is ordered alphabetically so the drop down
gives the options no, yes:

� Select � No Yes

instead of:

� Select � Yes No

Any thoughts?

Many thanks,

Mike

Hashes don’t guarantee any particular order. Not sure if rails is
sorting the hash by key as you suggest. Maybe try array of arrays.
Ordinarily I’d expect the order to be maintained since its an array, but
I’m not sure:

form.select :data , [[‘yes’,‘1’],[‘no’,‘0’]] , …

Regards,
Daniel

Splendid,
thanks.