I have this helper method in my application_helper, for some reason it
doesn''t output in the correct order:
def view_by_options(active)
html = "<strong>View The List
by:</strong> "
html +={ :popular => ''Most Popular'', :new =>
"Newest", :recommended =>
"Recommended"}.collect do |key,val|
link_to_unless (key.to_s == active, val, params.merge(:viewBy =>
key))
end.join(",")
html
end
resulting html always has ''newest, most popular, then
recommended'', not
''most popular, newest, recommended''.
When I run similar code in the console it works fine...any ideas?
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---
Gabriel Gironda
2007-May-29 19:18 UTC
Re: Hash.collect displaying in wrong order in view helper
http://corelib.rubyonrails.org/classes/Hash.html Hashes are unordered. If you want reliable ordering, you will need to use an Array. - Gabriel On 5/29/07, blinking bear <blinkingbear-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I have this helper method in my application_helper, for some reason it > doesn''t output in the correct order: > > def view_by_options(active) > html = "<strong>View The List by:</strong> " > html +={ :popular => ''Most Popular'', :new => "Newest", :recommended => > "Recommended"}.collect do |key,val| > link_to_unless (key.to_s == active, val, params.merge(:viewBy => > key)) > end.join(",") > html > end > > > resulting html always has ''newest, most popular, then recommended'', not > ''most popular, newest, recommended''. > > When I run similar code in the console it works fine...any ideas? > > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---