Files
nairobi/app/models/concerns/followable.rb
Javi Martín 884fd2b27b Add and apply Rails/WhereEquals rubocop rule
We were already following this style in most places.
2021-08-09 23:52:47 +02:00

17 lines
385 B
Ruby

module Followable
extend ActiveSupport::Concern
included do
has_many :follows, as: :followable, inverse_of: :followable, dependent: :destroy
has_many :followers, through: :follows, source: :user
scope :followed_by_user, ->(user) {
joins(:follows).where(follows: { user_id: user.id })
}
end
def followed_by?(user)
followers.include?(user)
end
end