Without additional information, you can try:
YourModel.group('country').order('count_country DESC').limit(3).count('country')
when you call the counter on field rails, it automatically adds a field to your request AS count_field_name.
The graph should be called at the end of the request because it returns an ordered hash.
source
share