From 2875a1235aac8d73b7beff89a6636569799c2b1b Mon Sep 17 00:00:00 2001 From: chiu Date: Fri, 20 Sep 2019 13:55:40 +0800 Subject: [PATCH] Update archives_controller.rb --- app/controllers/archives_controller.rb | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/app/controllers/archives_controller.rb b/app/controllers/archives_controller.rb index e692811..6272e89 100644 --- a/app/controllers/archives_controller.rb +++ b/app/controllers/archives_controller.rb @@ -11,7 +11,13 @@ class ArchivesController < ApplicationController if !params['title'].nil? files_by_cateogry = ArchiveFile.where(is_hidden: false).group_by(&:category) categories = files_by_cateogry.keys - categories_sort = categories.select{|category| all_categories_id.include? category.id.to_s} + categories_sort = [] + all_categories_id.each do |cat_id| + category_selected = categories.select{|category| cat_id == category.id.to_s} + if category_selected.length!=0 + categories_sort << category_selected[0] + end + end cats_last = [] categories_sort.each do |category| url_to_edit = "" @@ -71,7 +77,13 @@ class ArchivesController < ApplicationController files_by_cateogry = ArchiveFile.where(is_hidden: false).filter_by_categories.filter_by_tags.group_by(&:category) each_data_count = [] categories = files_by_cateogry.keys - categories_sort = categories.select{|category| all_categories_id.include? category.id.to_s} + categories_sort = [] + all_categories_id.each do |cat_id| + category_selected = categories.select{|category| cat_id == category.id.to_s} + if category_selected.length!=0 + categories_sort << category_selected[0] + end + end cats = categories_sort.collect do |category| url_to_edit = OrbitHelper.user_has_cateogry?(category) ? "/admin/archive_files?filters[category][]=#{category.id.to_s}" : "" archives = files_by_cateogry[category].collect do |archive|