class Rating
Public Instance Methods
rate(score, user)
click to toggle source
# File lib/app/models/rating.rb, line 7 def rate(score, user) user_ratings.find_or_initialize_by(user_id: user.id).update_attributes!(:score => score) reload end
update_rating()
click to toggle source
Call this method the update the avarage rating; you don’t normally need to do this manually, saving or updating a user rating already takes care of updating the avarage rating.
# File lib/app/models/rating.rb, line 15 def update_rating self.average_rating = user_ratings.average(:score) self.ratings_count = user_ratings.count save! end