Module: TheComments::Commentable
- Extended by:
- ActiveSupport::Concern
- Defined in:
- app/models/concerns/the_comments/commentable.rb
Instance Method Summary collapse
- #commentable_state ⇒ Object
-
#commentable_title ⇒ Object
Default Denormalization methods Overwrite it with your Application.
- #commentable_url ⇒ Object
-
#comments_sum ⇒ Object
Helper methods.
- #recalculate_comments_counters! ⇒ Object
Instance Method Details
#commentable_state ⇒ Object
26 27 28 29 |
# File 'app/models/concerns/the_comments/commentable.rb', line 26 def commentable_state # 'draft' try(:state) end |
#commentable_title ⇒ Object
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_url ⇒ Object
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_sum ⇒ Object
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 |