Files
grecia/app/models/concerns/followable.rb
Javi Martín f9ed186909 Add rubocop spacing rules
We were following these rules in most places; we just didn't define them
anywhere.
2019-09-10 21:04:56 +02:00

18 lines
362 B
Ruby

module Followable
extend ActiveSupport::Concern
included do
has_many :follows, as: :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