module ActsAsFavorite::Favor::InstanceMethods

Public Instance Methods

favorite_by(favoriter) click to toggle source
# 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) click to toggle source
# 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() click to toggle source

instance methods

# File lib/acts_as_favorite/favor.rb, line 22
def favorites_count
  favorites.count
end
unfavorite_by(favoriter) click to toggle source
# 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) click to toggle source
# 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