module ActsAsAble::Follower::InstanceMethods

Public Instance Methods

follow(obj) click to toggle source

1:   关注某人 2: 取消关注 3: 是否关注 4: 关注了某个 model 多少个 obj

# File lib/acts_as_able/follower.rb, line 21
def follow(obj)
  self.follows.find_or_create_by(followable_id: obj.id, followable_type: class_name(obj))
end
follow?(obj) click to toggle source
# File lib/acts_as_able/follower.rb, line 29
def follow?(obj)
  !get_follow_by_obj(obj).blank?
end
followings(followable_type) click to toggle source
# File lib/acts_as_able/follower.rb, line 33
def followings(followable_type)
  return followable_type.constantize.where(id: self.follows.where(followable_type: followable_type).pluck(:followable_id))
end
unfollow(obj) click to toggle source
# File lib/acts_as_able/follower.rb, line 25
def unfollow(obj)
  get_follow_by_obj(obj).destroy
end

Private Instance Methods

get_follow_by_obj(obj) click to toggle source
# File lib/acts_as_able/follower.rb, line 38
def get_follow_by_obj(obj)
  self.follows.find_by(followable_id: obj.id, followable_type: class_name(obj))
end