module ActsAsAble::Commenter::InstanceMethods

Public Instance Methods

comment(content, obj, parent_comment = nil) click to toggle source

评论某对象

# File lib/acts_as_able/commenter.rb, line 19
def comment(content, obj, parent_comment = nil)
  if parent_comment.present? && parent_comment.is_a?(Comment)
    self.comments.create(content: content,commentable_type: class_name(obj), commentable_id: obj.id, parent_id: parent_comment.id )
  else
    self.comments.create(content: content, commentable_type: class_name(obj), commentable_id: obj.id,)
  end
end
comment?(obj) click to toggle source

是否评论了某对象 & 回复了某对象的评论

# File lib/acts_as_able/commenter.rb, line 28
def comment?(obj)
  !comment_by(obj).blank?
end
commentings(commentable_type) click to toggle source

查看某种类型评论的所有对象

# File lib/acts_as_able/commenter.rb, line 33
def commentings(commentable_type)
  return commentable_type.constantize.where(id: self.comments.where(commentable_type: commentable_type).pluck(:commentable_id))
end

Private Instance Methods

comment_by(obj) click to toggle source
# File lib/acts_as_able/commenter.rb, line 39
def comment_by(obj)
  self.comments.find_by(commentable_type: class_name(obj), commentable_id: obj.id)
end