fix order problem for gallery index

This commit is contained in:
chiu 2020-01-19 11:27:55 +08:00
parent 285c62d5ab
commit 8770b54aff
1 changed files with 5 additions and 2 deletions

View File

@ -35,7 +35,10 @@ class GalleriesController < ApplicationController
end end
def index 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| galleries = albums.collect do |a|
doc = Nokogiri::HTML(a.description.to_s) doc = Nokogiri::HTML(a.description.to_s)
alt_text = doc.text.empty? ? 'gallery image' : doc.text alt_text = doc.text.empty? ? 'gallery image' : doc.text
@ -50,7 +53,7 @@ class GalleriesController < ApplicationController
{ {
"albums" => galleries, "albums" => galleries,
"extras" => {"widget-title"=>"Gallery"}, "extras" => {"widget-title"=>"Gallery"},
"total_pages" => albums.total_pages "total_pages" => album_tp.total_pages
} }
end end
def show def show