Module: ActsAsFollowable::Followable::ClassMethods

Defined in:
lib/acts_as_followable/followable.rb

Instance Method Summary collapse

Instance Method Details

#acts_as_followableObject



9
10
11
12
13
14
15
16
17
18
# File 'lib/acts_as_followable/followable.rb', line 9

def acts_as_followable
  include ActsAsFollowable::Lib::InstanceMethods
  include ActsAsFollowable::Followable::InstanceMethods
  
  scope :following, lambda{|followable| includes(:follows).where(['follows.followable_id=? AND follows.followable_type=?', followable.id, ActsAsFollowable::Lib.class_name(followable)]) }
  scope :followed_by, lambda{|follower| includes(:followings).where(['follows.follower_id=? AND follows.follower_type=?', follower.id, ActsAsFollowable::Lib.class_name(follower)]) }
  
  has_many :followings, :as => :followable, :dependent => :destroy, :class_name => 'Follow'
  has_many :follows, :as => :follower, :dependent => :destroy
end