0

I have a field in my database table called reputation.

It contains a hash.

Example: {:kout => 20, :google => 40 } etc...

When I get the records I want to sort them based upon a calculation performed with the values in that hash attribute.

I'm a NOOB and have no idea how to do this.

Any ideas welcome.

Rails 3.2

chell
  • 7,646
  • 16
  • 74
  • 140

1 Answers1

0

try this

http://www.rubyinside.com/how-to/ruby-sort-hash

open console and try this

h = {"a"=>100, "b"=>200, "c"=>150}
1.9.3p125 :023 > h.values.sort
=> [100, 150, 200] 
1.9.3p125 :024 > h.keys.sort
=> ["a", "b", "c"] 
Dipak Panchal
  • 5,996
  • 4
  • 32
  • 68