Module: IsRateable::ActsAsRateable::LocalInstanceMethods
- Defined in:
- lib/is_rateable/acts_as_rateable.rb
Instance Method Summary collapse
-
#add_rating(options = {}) ⇒ Object
Easily add a new rating to the object by calling Object.add_rating(score: 5, rater: user) Pass in the entire rater object in, rather than the id.
-
#any_ratings? ⇒ Boolean
Has this object been rated before?.
-
#average_rating ⇒ Object
Find the Average rating for the ratee.
Instance Method Details
#add_rating(options = {}) ⇒ Object
Easily add a new rating to the object by calling Object.add_rating(score: 5, rater: user) Pass in the entire rater object in, rather than the id.
30 31 32 |
# File 'lib/is_rateable/acts_as_rateable.rb', line 30 def ( = {}) Rating.create(score: [:score], rater: [:rater], ratee: self) end |
#any_ratings? ⇒ Boolean
Has this object been rated before?
24 25 26 |
# File 'lib/is_rateable/acts_as_rateable.rb', line 24 def .any? end |
#average_rating ⇒ Object
Find the Average rating for the ratee. Return 0.0 if they have not been rated yet.
19 20 21 |
# File 'lib/is_rateable/acts_as_rateable.rb', line 19 def ? ((.average(:score) * 10).round / 10.0) : 0.0 end |