> <%= select_tag(:order, options_for_select(@orders, > params[:order].to_s)) > %> > > I am using some data that is not in a database so I generated a hash > like the following: > > @orders = {''Name => ''name'', ''Rank'' => ''rank'', ''HP'' => ''hp'', ''SP'' => > ''sp''} etc... > > it works fine but the problem I have is that the hash is never in the > same order...after reading it looks like i should be using a struct or > an array. > > can someone help me convert this hash into an array or suggest the > best > way to do this?@orders = [[''Name'', ''name''], [''Rank'', ''rank''], ....] Should do it. Or you might need to swap ''name'' with ''Name''. I can never remember :) -philip --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
> @orders = [[''Name'', ''name''], [''Rank'', ''rank''], ....] > > Should do it. Or you might need to swap ''name'' with ''Name''. I can > never remember :) > > -philiphmm..i don''t think it likes it. it''s outputting this: <select id="order" name="order"> <option value="Namename">Namename</option> <option value="Rankrank">Rankrank</option> etc... i tried doing this: <%= select_tag(:order, options_for_select(@orders.collect{|order| [order[0], order[1]]}, params[:direction].to_s)) %> but ended up with this output: <select id="order" name="order"> <option value="">Namename</option> <option value="">Rankrank</option> etc... -- 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
>> @orders = [[''Name'', ''name''], [''Rank'', ''rank''], ....] >> >> Should do it. Or you might need to swap ''name'' with ''Name''. I can >> never remember :) >> >> -philip > > hmm..i don''t think it likes it.Strange. It should. Docs say: options_for_select([["Dollar", "$"], ["Kroner", "DKK"]]) <option value="$">Dollar</option>\n<option value="DKK">Kroner</ option>> it''s outputting this: > > <select id="order" name="order"> > <option value="Namename">Namename</option> > <option value="Rankrank">Rankrank</option> > etc... > > i tried doing this: > > <%= select_tag(:order, options_for_select(@orders.collect{|order| > [order[0], order[1]]}, params[:direction].to_s)) %> > > but ended up with this output: > > <select id="order" name="order"> > <option value="">Namename</option> > <option value="">Rankrank</option> > etc... > -- > 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---