Module: TheComments::Commentable

Extended by:
ActiveSupport::Concern
Defined in:
app/models/concerns/the_comments/commentable.rb

Instance Method Summary collapse

Instance Method Details

#commentable_stateObject



26
27
28
29
# File 'app/models/concerns/the_comments/commentable.rb', line 26

def commentable_state
  # 'draft'
  try(:state)
end

#commentable_titleObject

Default Denormalization methods Overwrite it with your Application



16
17
18
19
# File 'app/models/concerns/the_comments/commentable.rb', line 16

def commentable_title
  # My first blog post
  try(:title) || TheComments.config.default_title
end

#commentable_urlObject



21
22
23
24
# File 'app/models/concerns/the_comments/commentable.rb', line 21

def commentable_url
  # /posts/1
  ['', self.class.to_s.tableize, self.to_param].join('/')
end

#comments_sumObject

Helper methods



32
33
34
# File 'app/models/concerns/the_comments/commentable.rb', line 32

def comments_sum
  published_comments_count + draft_comments_count
end

#recalculate_comments_counters!Object



36
37
38
39
40
41
42
# File 'app/models/concerns/the_comments/commentable.rb', line 36

def recalculate_comments_counters!
  update_attributes!({
    draft_comments_count:     comments.with_state(:draft).count,
    published_comments_count: comments.with_state(:published).count,
    deleted_comments_count:   comments.with_state(:deleted).count
  })
end