From 7568aaafaf38cf0b29dd2f6de02c335fb0d67691 Mon Sep 17 00:00:00 2001 From: chiu Date: Fri, 17 Sep 2021 13:43:32 +0800 Subject: [PATCH] fix error --- app/models/archive_category.rb | 2 +- app/models/archive_file.rb | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/app/models/archive_category.rb b/app/models/archive_category.rb index 2ff21e8..4c9e5a8 100644 --- a/app/models/archive_category.rb +++ b/app/models/archive_category.rb @@ -6,7 +6,7 @@ class ArchiveCategory if(!record.new_record? && record.sort_number.class != Fixnum) record.sort_number = 0 record.save - elsif(!record.new_record?) + elsif(!record.new_record?) @category = Category.find(record.category_id) rescue nil if !@category.nil? @sort_number = @category.sort_number rescue nil diff --git a/app/models/archive_file.rb b/app/models/archive_file.rb index 715dd3d..ee2542b 100644 --- a/app/models/archive_file.rb +++ b/app/models/archive_file.rb @@ -15,7 +15,12 @@ class ArchiveFile # BelongsToCategory = :archive_file_category # PAYMENT_TYPES = @site_valid_locales - + before_save do + cat = self.category rescue nil + if cat && ArchiveCategory.where(:category_id => cat.id).count==0 + ArchiveCategory.create(category_id: cat.id.to_s) + end + end field :title, as: :slug_title, localize: true field :description, localize: true