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 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
<%= f.select( :data, { "Yes" => "1", "No" => "0"}.sort.reverse, {:prompt => "– Select –"}) %> On Oct 16, 11:37 am, mikej <mikejerem...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> 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--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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, > > MikeHashes 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 -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Splendid, thanks. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---