From 8770b54aff575643af1a01419a6f4875c63de789 Mon Sep 17 00:00:00 2001 From: chiu Date: Sun, 19 Jan 2020 11:27:55 +0800 Subject: [PATCH] fix order problem for gallery index --- app/controllers/galleries_controller.rb | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/app/controllers/galleries_controller.rb b/app/controllers/galleries_controller.rb index 1d06cba..bdafa4b 100644 --- a/app/controllers/galleries_controller.rb +++ b/app/controllers/galleries_controller.rb @@ -35,7 +35,10 @@ class GalleriesController < ApplicationController end def index - albums = Album.filter_by_categories.filter_by_tags.asc(:order) + album_tp = Album.filter_by_categories.filter_by_tags + albums_no_order = album_tp.desc(:created_at).select{|v| v.order == -1} + albums_with_order = album_tp.asc(:order).select{|v| v.order != -1} + albums = albums_no_order.concat(albums_with_order) galleries = albums.collect do |a| doc = Nokogiri::HTML(a.description.to_s) alt_text = doc.text.empty? ? 'gallery image' : doc.text @@ -50,7 +53,7 @@ class GalleriesController < ApplicationController { "albums" => galleries, "extras" => {"widget-title"=>"Gallery"}, - "total_pages" => albums.total_pages + "total_pages" => album_tp.total_pages } end def show