Skip to content

Commit 6b2ef7a

Browse files
committed
extract protip comments to partial
1 parent ef30af9 commit 6b2ef7a

File tree

3 files changed

+11
-9
lines changed

3 files changed

+11
-9
lines changed

app/models/comment.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ class Comment < ActiveRecord::Base
3434

3535
belongs_to :user, autosave: true
3636

37+
scope :showable, ->{ with_states(:active,:reported_as_spam) }
38+
3739
alias_method :author, :user
3840
alias_attribute :body, :comment
3941

app/views/protips/_protip.html.haml

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -104,15 +104,7 @@
104104
%div.tip-content{itemprop: :articleBody}
105105
= raw sanitize(protip.to_html)
106106

107-
- if include_comments
108-
%section.comments{ class:('no-comments' if protip.comments.empty? ) }
109-
- if protip.comments.any?
110-
%h2.comments-header
111-
%i.fa.fa-comments
112-
Comments
113-
%ul.comment-list
114-
= render protip.comments.with_states(:active,:reported_as_spam)
115-
= render 'comments/add_comment'
107+
= render('protip_comments', comments: protip.comments.showable) if include_comments
116108

117109
- if defined?(:job) && !job.nil?
118110
.mobile-job
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
section.comments class=('no-comments' if comments.empty? )
2+
- if comments.any?
3+
h2.comments-header
4+
i.fa.fa-comments
5+
| Comments
6+
ul.comment-list
7+
= render comments
8+
= render 'comments/add_comment'

0 commit comments

Comments
 (0)