Module: Acts::CommentableWithThreading::InstanceMethods

Defined in:
lib/acts_as_commentable_with_threading.rb

Overview

This module contains instance methods

Instance Method Summary collapse

Instance Method Details

#add_comment(comment) ⇒ Object

Helper method that defaults the submitted time.



60
61
62
# File 'lib/acts_as_commentable_with_threading.rb', line 60

def add_comment(comment)
  comments << comment
end

#can_comment?(user) ⇒ Boolean

Determines whether or not the give user can comment on the parent object

Returns:

  • (Boolean)


65
66
67
68
# File 'lib/acts_as_commentable_with_threading.rb', line 65

def can_comment?(user)
  return true unless user.blank?
  false
end

#comments_ordered_by_submittedObject

Helper method to sort comments by date



52
53
54
55
56
57
# File 'lib/acts_as_commentable_with_threading.rb', line 52

def 
  Comment.find(:all,
    :conditions => ["commentable_id = ? and commentable_type = ?", id, self.class.name],
    :order => "created_at DESC"
  )
end

#root_commentsObject

Helper method to display only root threads, no children/replies



47
48
49
# File 'lib/acts_as_commentable_with_threading.rb', line 47

def root_comments
  self.comments.find(:all, :conditions => {:parent_id => nil})
end