Forum: Ruby on Rails changing order of hash

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
David N. (Guest)
on 2009-01-07 13:08
I've got a constant of difficulty levels in my 'Tutorial' model which is
a hash of

DIFFICULTIES = {"Beginner" => 1, "Intermediate" => 2, "Advanced" => 3}

However when I pass it to my options_for_select helper they appear in a
completely different order. Is there any way to keep them in the correct
order?

Also is this the best way to keep a small list like this that isn't
related to a database table?
Frederick C. (Guest)
on 2009-01-07 13:49
(Received via mailing list)
On 7 Jan 2009, at 11:08, David Nicholson wrote:

> correct
> order?
>
Hashes are unordered (at least in ruby 1.8). As far as
options_for_select is concerned you can use something like
[['Beginner', 1], ...]


> Also is this the best way to keep a small list like this that isn't
> related to a database table?

constant in the tutorial model sounds fine to me.

Fred
Christoph J. (Guest)
on 2009-01-07 14:15
(Received via mailing list)
Can't you use .sort Method or switch to Ruby 1.9?
Here a tip from Ezra Z.
http://www.ruby-forum.com/topic/50146#16582

Chris
David N. (Guest)
on 2009-01-07 17:56
Thanks a lot

The array method did the trick.
This topic is locked and can not be replied to.