Created
December 24, 2016 18:13
-
-
Save bleonard/9d2fabd43ad58e62246212da727581cf 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
| # initializer | |
| ResqueBus.dispatch("profile") do | |
| subscribe "rating_created" do |attributes| | |
| rating = Rating.find(rating_id) | |
| total = Rating.where(rabbit_id: rating.rabbit_id).count | |
| sum = Rating.where(rabbit_id: rating.rabbit_id').sum(:value) | |
| profile = RabbitProfile.find_by(user_id: rating.rabbit_id) | |
| profile.ratings_total = total | |
| profile.rating_average = sum.to_f / (5*total.to_f) | |
| profile.save! | |
| end | |
| end |
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 Rating < ActiveRecord::Base | |
| after_commit :enqueue_worker | |
| def enqueue_worker | |
| ResqueBus.publish("rating_created", self.attributes) | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment