mikej
(mikej)
October 16, 2008, 9:37am
1
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
tejo
(tejo)
October 16, 2008, 10:48am
2
<%= f.select( :data, { "Yes" => "1", "No" => "0"}.sort.reverse,
{:prompt => "–
Select –"}) %>
11175
(-- --)
October 16, 2008, 10:58am
3
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