]> gitweb.mndrdr.org Git - arelpe.git/commitdiff
query fixed
authorAidan Cornelius-Bell <[email protected]>
Mon, 23 Sep 2024 02:55:31 +0000 (12:25 +0930)
committerAidan Cornelius-Bell <[email protected]>
Mon, 23 Sep 2024 02:55:31 +0000 (12:25 +0930)
app/controllers/pubview_controller.rb

index f03db8b169f999efb8956f5f79e87c6913540e50..bfbd85afaf7e127680329993a584dc4e90ed482a 100644 (file)
@@ -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