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