From 40c29eb6fb44e65f15ab57481c640be4ad2beaa9 Mon Sep 17 00:00:00 2001 From: chiu Date: Wed, 18 Sep 2019 20:59:38 +0800 Subject: [PATCH] Update archive_files_controller.rb --- app/controllers/admin/archive_files_controller.rb | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/app/controllers/admin/archive_files_controller.rb b/app/controllers/admin/archive_files_controller.rb index 41aec4c..a847f1c 100644 --- a/app/controllers/admin/archive_files_controller.rb +++ b/app/controllers/admin/archive_files_controller.rb @@ -50,7 +50,18 @@ class Admin::ArchiveFilesController < OrbitAdminController end end def categories_order - @categories = @module_app.categories + categories = @module_app.categories + categories.each do |category| + archive_cat = ArchiveCategory.All.select{ |value| value.category_id.to_s == category.id.to_s} + if archive_cat.length == 0 + ArchiveCategory.create(category_id: category.id.to_s) + end + end + cats_with_nil = ArchiveCategory.All.in(sort_number: nil) + cats_no_nil = ArchiveCategory.All.not_in(sort_number: nil) + @cats = cats_no_nil.concat(cats_with_nil).collect do |cat| + [categories.where(:_id => cat.category_id).first,cat.sort_number.to_s] + end render :partial => "categories_order" if request.xhr? end def create