Skip to content

Instantly share code, notes, and snippets.

@bleonard
Created December 24, 2016 18:25
Show Gist options
  • Save bleonard/4f0c259d1ee9daf532ba822653ddacf1 to your computer and use it in GitHub Desktop.
Save bleonard/4f0c259d1ee9daf532ba822653ddacf1 to your computer and use it in GitHub Desktop.
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