docbrown/app/controllers/internal/comments_controller.rb
Michael Kohl a4dadfb728
Standardize ActiveRecord order clauses (#9395)
* Change simple order clauses

* Change nested order clauses
2020-07-20 10:00:51 -04:00

28 lines
887 B
Ruby

module Internal
class CommentsController < Internal::ApplicationController
layout "internal"
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
private
def authorize_admin
authorize Comment, :access?, policy_class: InternalPolicy
end
end
end