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 id="my_id" name="my[data]" > <option value="">– Select –</option> <option value="0">No</option> <option value="1">Yes</option> </select>

instead of:

<select id="my_id" name="my[data]" > <option value="">– Select –</option> <option value="1">Yes</option> <option value="0">No</option> </select>

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 id="my_id" name="my[data]" > <option value="">� Select �</option> <option value="0">No</option> <option value="1">Yes</option> </select>

instead of:

<select id="my_id" name="my[data]" > <option value="">� Select �</option> <option value="1">Yes</option> <option value="0">No</option> </select>

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.