init project

This commit is contained in:
Jasder
2020-03-09 00:40:16 +08:00
commit 2937b2a94d
6549 changed files with 7215173 additions and 0 deletions

View File

@@ -0,0 +1,21 @@
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