forked from jasder/forgeplus
22 lines
449 B
Ruby
22 lines
449 B
Ruby
module Likeable
|
|
extend ActiveSupport::Concern
|
|
|
|
included do
|
|
has_many :praise_treads, as: :praise_tread_object, dependent: :destroy
|
|
end
|
|
|
|
def liked?(praiseable)
|
|
praiseable.praise_treads.exists?(user_id: self.id)
|
|
end
|
|
|
|
def like!(praiseable)
|
|
praiseable.praise_treads.create!(user_id: self.id)
|
|
end
|
|
|
|
def unlike!(praiseable)
|
|
obj = praiseable.praise_treads.find_by(user_id: self.id)
|
|
obj.destroy! if obj.present?
|
|
end
|
|
|
|
end
|