Class: Rating
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Rating
- Defined in:
- lib/rating.rb
Instance Method Summary collapse
- #rate(score, user) ⇒ Object
-
#update_rating ⇒ Object
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.
Instance Method Details
#rate(score, user) ⇒ Object
7 8 9 10 |
# File 'lib/rating.rb', line 7 def rate(score, user) .find_or_initialize_by_user_id(user.id).update_attributes!(:score => score) reload end |
#update_rating ⇒ Object
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 self. = .average(:score) self. = .count save! end |