I’ve got an active record query where I’m using group_by
@foo = Foo.group_by(&:relation)
Then in the view i’m using
@foo.each do |group, values|
group x has values.count elements
end
Is there a way I could sort these by the count of each group?
group_by is not a ActiveRecord method, group is. group_by is a Enumerator method.
What about
Taken from "Order by" result of "group by" count?.
Otherwise, if you want to sort it on Ruby level, you could do