From 5bad5c6012e73e26fd9fcfff418e0c83ce0fb90b Mon Sep 17 00:00:00 2001 From: evazion Date: Tue, 18 Aug 2020 13:56:44 -0500 Subject: [PATCH] comments: fix `visible` method conflict. Fix the `Comment#visible` method conflicting with the base class `visible` method defined in ApplicationRecord. --- app/controllers/posts_controller.rb | 2 +- app/models/comment.rb | 3 +-- app/views/comments/_index_by_post.html.erb | 4 ++-- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/app/controllers/posts_controller.rb b/app/controllers/posts_controller.rb index d5ac0e24e..160a10633 100644 --- a/app/controllers/posts_controller.rb +++ b/app/controllers/posts_controller.rb @@ -25,7 +25,7 @@ class PostsController < ApplicationController @comments = @post.comments @comments = @comments.includes(:creator) @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? @sibling_posts = @post.parent.present? ? @post.parent.children : Post.none diff --git a/app/models/comment.rb b/app/models/comment.rb index ade9a8073..0c4fd1f8d 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -131,8 +131,7 @@ class Comment < ApplicationRecord select { |comment| comment.visibility(user) == :hidden } end - # XXX rename - def self.visible(user) + def self.unhidden(user) select { |comment| comment.visibility(user) == :visible } end diff --git a/app/views/comments/_index_by_post.html.erb b/app/views/comments/_index_by_post.html.erb index 549d17557..cc217a7a9 100644 --- a/app/views/comments/_index_by_post.html.erb +++ b/app/views/comments/_index_by_post.html.erb @@ -4,12 +4,12 @@ <% end %> <% @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 %>
<%= link_to(image_tag(post.preview_file_url), post_path(post)) %>
- <%= 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 %>