开发者

why does heroku change the order of hashes?

for the life of me i could not figure this out.

if i have this in my local dev/production:

fields = { :name => { ...}, :description => { ...}, :amount => { .... } }

its fine i loop through my hashes and print the fields name just like how i declared it.

In heroku, the sequence is different in printed order?? I have complete no idea why and i can't get a clue why heroku is printing them in different order.

does that make sense?

Edit: OMG its driving me nuts. I actually do this in my templat, sorting my variable but For some reaaaaaly weird reason, its still coming out in a ma开发者_JAVA技巧nner heroku only understands.

- @form_columns = @form_columns.sort_by do |i| 
  - if i[1][:rank].nil?
    - i[1][:rank] = rank
  - i[1][:rank]  
  - rank = rank + 1 

This is how i loop by the way:

  • @form_columns.each do |column_name|

Please understand that there is no issue in my local production/dev server.


If you for some reason have to use Ruby 1.8 then you can get an ordered hash by using OrderedHash in Rails ActiveSupport.

To see what stack you are using on Heroku:

heroku stack

and to migrate to 1.9.2:

heroku stack:migrate bamboo-mri-1.9.2


The order of keys within a Hash is not guaranteed to equal the order in which were inserted, in Ruby 1.8

That behaviour is different in Ruby 1.9, where the order is preserved.

http://www.igvita.com/2009/02/04/ruby-19-internals-ordered-hash/

Are you using ruby 1.8?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜