Module: ActsAsFavorite::Favor::InstanceMethods
- Defined in:
- lib/acts_as_favorite/favor.rb
Instance Method Summary collapse
- #favorite_by(favoriter) ⇒ Object
- #favorite_by?(favoriter) ⇒ Boolean
-
#favorites_count ⇒ Object
instance methods.
- #unfavorite_by(favoriter) ⇒ Object
- #update_favorite(id, favoriter) ⇒ Object
Instance Method Details
#favorite_by(favoriter) ⇒ Object
30 31 32 |
# File 'lib/acts_as_favorite/favor.rb', line 30 def favorite_by(favoriter) favorites.create(favoriter_id: favoriter.id, favoriter_type: favoriter.class.base_class.name) end |
#favorite_by?(favoriter) ⇒ Boolean
26 27 28 |
# File 'lib/acts_as_favorite/favor.rb', line 26 def favorite_by?(favoriter) favorites.find_by(favoriter_id: favoriter.id, favoriter_type: favoriter.class.base_class.name).present? end |
#favorites_count ⇒ Object
instance methods
22 23 24 |
# File 'lib/acts_as_favorite/favor.rb', line 22 def favorites_count favorites.count end |
#unfavorite_by(favoriter) ⇒ Object
34 35 36 37 |
# File 'lib/acts_as_favorite/favor.rb', line 34 def unfavorite_by(favoriter) records = favorites.find_by(favoriter_id: favoriter.id, favoriter_type: favoriter.class.base_class.name) records.try(:destroy) end |
#update_favorite(id, favoriter) ⇒ Object
39 40 41 42 |
# File 'lib/acts_as_favorite/favor.rb', line 39 def update_favorite(id, favoriter) records = favorites.find(id) records.update_attributes(favoriter_id: favoriter.id, favoriter_type: favoriter.class.base_class.name) end |