diff --git a/app/controllers/archives_controller.rb b/app/controllers/archives_controller.rb index ea40595..73f08b3 100644 --- a/app/controllers/archives_controller.rb +++ b/app/controllers/archives_controller.rb @@ -1,12 +1,5 @@ class ArchivesController < ApplicationController #avoid the categories to be not in the ArchiveCategory - categories_temp = ModuleApp.where(:key => "archive").first.categories - categories_temp.each do |category| - archive_cat = ArchiveCategory.where(:category_id => category.id) - if archive_cat.count == 0 - ArchiveCategory.create(category_id: category.id.to_s) - end - end def serve_cmap serve_path=File.expand_path("../../assets/javascripts/archive/pdf/bcmaps/#{params[:file_name]}.#{params[:extension]}",__FILE__) if Dir.glob(serve_path).length != 0 diff --git a/lib/archive/engine.rb b/lib/archive/engine.rb index 225657a..24fd16a 100644 --- a/lib/archive/engine.rb +++ b/lib/archive/engine.rb @@ -1,6 +1,23 @@ module Archive class Engine < ::Rails::Engine + initializer "archive" do + require File.expand_path('../../../app/models/archive_category', __FILE__) + require "#{ENV['PWD']}/app/models/category" + require "#{ENV['PWD']}/app/models/module_app" + + categories_temp = ModuleApp.where(:key => "archive").first.categories + + categories_temp.each do |category| + archive_cat = ArchiveCategory.where(:category_id => category.id) + if archive_cat.count == 0 + ArchiveCategory.create(category_id: category.id.to_s) + else + archive_cat[1..-1].each do |cat| + cat.delete + end + end + end OrbitApp.registration "Archive", :type => "ModuleApp" do module_label "archive.archive" base_url File.expand_path File.dirname(__FILE__)