module ThreadableComments::InstanceMethods

Public Instance Methods

add_comment(text, user, parameters = {}) click to toggle source
# File lib/threadable_comments.rb, line 28
def add_comment(text, user, parameters = {})
  new_comment = ThreadableComments::Comment.create(commentable: self,
                                                   text: text,
                                                   user_id: user.id,
                                                   parameters: parameters)
  comments << new_comment
  new_comment
end
comments_by(user) click to toggle source

scope comments to specific user

# File lib/threadable_comments.rb, line 22
def comments_by(user)
  raise ArgumentError.new("User must have an ID property") unless user.respond_to? :id

  comments.where(user_id: user.id)
end
root_comments() click to toggle source

Scope comments to only root threads, no children/replies

# File lib/threadable_comments.rb, line 17
def root_comments
  comments.roots
end