bouchard / thumbs_up

Dead-Simple Vote and Karma Management

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Calculating total karma for a user

Brotakuu opened this issue · comments

What would be the best way to calculate the total number of votes a user has received? (ie: tally all votes from posts a user created).

Would the best approach be to create a counter that increments everytime a vote is cast? Or is there a built in method that can tally the total?

Thanks, that was exactly what I was looking for. I tried to search online for what you mean by denormalize this to the User model. Would you mind explaining or adding an example?

Do you mean create a method in the model like:

def get_karma
    return self.posts.map(&:votes_for).sum
end