Class: Rating

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
lib/rating.rb

Instance Method Summary collapse

Instance Method Details

#rate(score, user) ⇒ Object



7
8
9
10
# File 'lib/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_ratingObject

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.



15
16
17
18
19
# File 'lib/rating.rb', line 15

def update_rating
  self.average_rating = user_ratings.average(:score)
  self.ratings_count = user_ratings.count
  save!
end