Module: ActsAsAble::Follower::InstanceMethods

Defined in:
lib/acts_as_able/follower.rb

Instance Method Summary collapse

Instance Method Details

#follow(obj) ⇒ Object

# 1:   关注某人

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


21
22
23
# 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) ⇒ Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/acts_as_able/follower.rb', line 29

def follow?(obj)
  !get_follow_by_obj(obj).blank?
end

#followings(followable_type) ⇒ Object



33
34
35
# 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) ⇒ Object



25
26
27
# File 'lib/acts_as_able/follower.rb', line 25

def unfollow(obj)
  get_follow_by_obj(obj).destroy
end