Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Calculating total karma for a user #110

Open
Brotakuu opened this issue Mar 14, 2017 · 3 comments
Open

Calculating total karma for a user #110

Brotakuu opened this issue Mar 14, 2017 · 3 comments

Comments

@Brotakuu
Copy link

Brotakuu commented Mar 14, 2017

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?

@bouchard
Copy link
Owner

bouchard commented Mar 14, 2017 via email

@Brotakuu
Copy link
Author

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

@bouchard
Copy link
Owner

bouchard commented Mar 14, 2017 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants