comments: fix visible method conflict.

Fix the `Comment#visible` method conflicting with the base class
`visible` method defined in ApplicationRecord.
This commit is contained in:
evazion
2020-08-18 13:56:44 -05:00
parent 70b82010a7
commit 5bad5c6012
3 changed files with 4 additions and 5 deletions

View File

@@ -25,7 +25,7 @@ class PostsController < ApplicationController
@comments = @post.comments @comments = @post.comments
@comments = @comments.includes(:creator) @comments = @comments.includes(:creator)
@comments = @comments.includes(:votes) if CurrentUser.is_member? @comments = @comments.includes(:votes) if CurrentUser.is_member?
@comments = @comments.visible(CurrentUser.user) @comments = @comments.unhidden(CurrentUser.user)
include_deleted = @post.is_deleted? || (@post.parent_id.present? && @post.parent.is_deleted?) || CurrentUser.user.show_deleted_children? include_deleted = @post.is_deleted? || (@post.parent_id.present? && @post.parent.is_deleted?) || CurrentUser.user.show_deleted_children?
@sibling_posts = @post.parent.present? ? @post.parent.children : Post.none @sibling_posts = @post.parent.present? ? @post.parent.children : Post.none

View File

@@ -131,8 +131,7 @@ class Comment < ApplicationRecord
select { |comment| comment.visibility(user) == :hidden } select { |comment| comment.visibility(user) == :hidden }
end end
# XXX rename def self.unhidden(user)
def self.visible(user)
select { |comment| comment.visibility(user) == :visible } select { |comment| comment.visibility(user) == :visible }
end end

View File

@@ -4,12 +4,12 @@
<% end %> <% end %>
<% @posts.select(&:visible?).each do |post| %> <% @posts.select(&:visible?).each do |post| %>
<% if post.comments.visible(CurrentUser.user).any? || post.comments.hidden(CurrentUser.user).any? %> <% if post.comments.unhidden(CurrentUser.user).any? || post.comments.hidden(CurrentUser.user).any? %>
<%= content_tag(:div, { id: "post_#{post.id}", class: ["post", *PostPresenter.preview_class(post)].join(" ") }.merge(PostPresenter.data_attributes(post))) do %> <%= content_tag(:div, { id: "post_#{post.id}", class: ["post", *PostPresenter.preview_class(post)].join(" ") }.merge(PostPresenter.data_attributes(post))) do %>
<div class="preview"> <div class="preview">
<%= link_to(image_tag(post.preview_file_url), post_path(post)) %> <%= link_to(image_tag(post.preview_file_url), post_path(post)) %>
</div> </div>
<%= render "comments/partials/index/list", post: post, comments: post.comments.visible(CurrentUser.user).last(6), page: :comments %> <%= render "comments/partials/index/list", post: post, comments: post.comments.unhidden(CurrentUser.user).last(6), page: :comments %>
<% end %> <% end %>
<% end %> <% end %>
<% end %> <% end %>