Given the following model:
class Vote < ActiveRecord::Base attr_accessible :user_id, :vote_for_id, :voting_category_id, ,:points_earned belongs_to :user belongs_to :vote_for belongs_to :voting_category
I would like to know how to make a query for a PostgreSQL database that returns a leading board. In other words, the total score for each user, sorted from first to last?
So far, I:
Votes.sum(:points_earned).group(:user_id, :id).order(:points_earned)
Thanks in advance
source share