Created
December 24, 2016 18:25
-
-
Save bleonard/4f0c259d1ee9daf532ba822653ddacf1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Profile::ContentSubscriber | |
include ResqueBus::Subscriber | |
subscribe :post_rated | |
def post_rated(attributes) | |
total = Profile::Rate.where(author_id: attributes['author_id']).count | |
sum = Profile::Rate.where(author_id: attributes['author_id']).sum(:rating) | |
profile = Profile::Document.find_by(user_id: attributes['post_author_id']) | |
profile.post_ratings_total = total | |
profile.post_rating_average = sum.to_f / (5*total.to_f) | |
profile.save! | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment