Forum: Ruby on Rails Hash.collect displaying in wrong order in view helper

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
181976602397443ce119909b9d82cae2?d=identicon&s=25 blinking bear (Guest)
on 2007-05-29 21:08
(Received via mailing list)
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>&nbsp;&nbsp;"
    html +={ :popular => 'Most Popular', :new => "Newest", :recommended
"Recommended"}.collect do |key,val|
       link_to_unless (key.to_s == active, val, params.merge(:viewBy =>

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?
Fc49ff6d82732b73a94be2974b4dd3df?d=identicon&s=25 Gabriel Gironda (Guest)
on 2007-05-29 21:20
(Received via mailing list)

Hashes are unordered. If you want reliable ordering, you will need to
use an Array.

- Gabriel
This topic is locked and can not be replied to.