From: Aidan Cornelius-Bell Date: Mon, 23 Sep 2024 02:55:31 +0000 (+0930) Subject: query fixed X-Git-Url: https://gitweb.mndrdr.org/?a=commitdiff_plain;h=14d971d45b34c90ec757f0591f4dc388d6c2353a;p=arelpe.git query fixed --- diff --git a/app/controllers/pubview_controller.rb b/app/controllers/pubview_controller.rb index f03db8b..bfbd85a 100644 --- a/app/controllers/pubview_controller.rb +++ b/app/controllers/pubview_controller.rb @@ -1,7 +1,7 @@ class PubviewController < ApplicationController - def index - @pages = Page.where(visibility: :visible).order(created_at: :asc).first(2).sort_by { |item| item.downcase } - + before_action :set_pages, only: [:index, :show_public] + + def index @per_page = 15 @page = params[:page].to_i || 1 @filter = params[:filter] || 'all' @@ -11,9 +11,7 @@ class PubviewController < ApplicationController @current_page = @items.current_page end - def show_public - @pages = Page.where(visibility: :visible).order(created_at: :asc).first(2).sort_by { |item| item.downcase } - + def show_public if current_user&.admin? @page = Page.find_by(slug: params[:slug], visibility: ['visible', 'user_only', 'admin_only']) elsif current_user @@ -66,4 +64,14 @@ class PubviewController < ApplicationController word_count = content.split.size (word_count / 200.0).ceil end + + def set_pages + @pages = Page.where(visibility: :visible) + .order(Arel.sql("CASE + WHEN title = 'About' THEN 1 + WHEN title = 'Sponsorship' THEN 2 + ELSE 3 + END")) + .limit(2) + end end