Sorting hash?

Hello RoR Developers,

I have tiny problem with sorting hash. I can not sort hash values.

i have hash which is created by yaml file.
yaml file

template1:
template_of_roster3: template_of_roster2
template_of_roster4: template_of_roster3

controller:

@get_config=YAML.load(File.open("#{PATH_IM}/…yml"))
@get_config == Hash
@enterprises==Hash
@my_hash=@get_config[“template1”]

and I use this hash in my selection like

view:

<%
templateOptions = “”
@sites.each do |key,value|
templateOptions = templateOptions + “#{value}”
end
%>
<%=select_tag “templates”, templateOptions,{‘style’ =>
‘width:100px’ } %>

in fact there is no problem here but when I update my hash like this
@new_hash={“new_hash”=>“new_hash”}
@my_hash.update(@new_hash)

it s sorted like,
new_hash
template_of_roster2
template_of_roster3

but I want to see new_hash at the last option. how can I do it? any
idea.

thanks

On 5 Mar 2008, at 02:40, Ibrahim D. wrote:

Hello RoR Developers,

but I want to see new_hash at the last option. how can I do it? any
idea.

By not using a hash. A hash just isn’t ordered in ruby (in 1.9 they
are ordered by the order of insertion). ActiveSupport also provides an
OrderedHash class.

Fred

I think you have to do something like this

<%
templateOptions = “”
@sites.sort {|key,value| value[1]<=>key[1]}.each do |
v|
templateOptions = templateOptions + “#{v[1]}”
end
%>
<%=select_tag “templates”, templateOptions,{‘style’ =>
‘width:100px’ } %>

try it out

On Mar 5, 7:40 am, Ibrahim D. [email protected]