Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

相談部屋のコメントを省いたコメント数を出力するようにした #8223

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions app/models/comment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ class Comment < ApplicationRecord

mentionable_as :description, hook_name: :after_commit

scope :without_talk, -> { where.not(commentable_type: 'Talk') }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

新しくスコープを定義して「相談部屋以外のコメント」を抽出しやすくしたのが分かりやすくて良いなと思いました!

一方、今回の PR で表示数を揃えようとしているもう片側の「ユーザーページの上部タブにあるコメント(既に相談部屋のコメントは省かれている)」の数値取得の方( app/helpers/page_tabs/users_helper.rb 内)でも where.not(commentable_type: 'Talk') の表記がこのまま使われているようでしたので、 users_helper.rb 内の方も without_talk スコープに置き換えて良さそうに思ったのですが、いかがでしょうか?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

確かにおっしゃる通りです!ご指摘ありがとうございます!
スコープに置き換えます👍


class << self
def commented_users
User.with_attached_avatar
Expand Down
4 changes: 2 additions & 2 deletions app/views/users/_activity_counts.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ dl.card-counts__items
dt.card-counts__item-label
| コメント
dd.card-counts__item-value
= link_to_if !user.comments.empty?,
user.comments.size, user_comments_path(user)
= link_to_if !user.comments.without_talk.empty?,
user.comments.without_talk.size, user_comments_path(user)
.card-counts__item
.card-counts__item-inner
dt.card-counts__item-label
Expand Down