docbrown/app/controllers/admin/comments_controller.rb
Rajat Talesra bc2d7702ee
Standalone "admin" page for each comment (#19644)
* Created separate comments page

* Optimised code for single comment and multiple comments

* Indifual comments poage added

* Minor header change

* Created show method

* Applied review changes

* Removed like button from admin comments page
2023-06-30 00:31:07 +05:30

32 lines
973 B
Ruby

module Admin
class CommentsController < Admin::ApplicationController
layout "admin"
def index
@comments = if params[:state]&.start_with?("toplast-")
Comment
.includes(:user)
.includes(:commentable)
.order(public_reactions_count: :desc)
.where("created_at > ?", params[:state].split("-").last.to_i.days.ago)
.page(params[:page] || 1).per(50)
else
Comment
.includes(:user)
.includes(:commentable)
.order(created_at: :desc)
.page(params[:page] || 1).per(50)
end
end
def show
@comment = Comment.includes(:user, :commentable).find(params[:id])
end
private
def authorize_admin
authorize Comment, :access?, policy_class: InternalPolicy
end
end
end