group_by is not an ActiveRecord method, but a group. group_by is an Enumerator method.
What about
@foo = Foo.group('relation').order('count_id asc').count('id')
Taken from the "Order" result of the "group by" count? .
Otherwise, if you want to sort it at the Ruby level, you can do
disordered_hash = {:two=>[1, 2], :one=>[1], :three=>[1, 2, 3]} ordered_array = disordered_hash.sort {|k, v| k[1].count <=> v[1].count}
source share