Module: ThreadableComments::InstanceMethods

Defined in:
lib/threadable_comments.rb

Instance Method Summary collapse

Instance Method Details

#add_comment(text, user, parameters = {}) ⇒ Object



28
29
30
31
32
33
34
35
# 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) ⇒ Object

scope comments to specific user

Raises:

  • (ArgumentError)


22
23
24
25
26
# 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_commentsObject

Scope comments to only root threads, no children/replies



17
18
19
# File 'lib/threadable_comments.rb', line 17

def root_comments
  comments.roots
end