From a355b30fbf5127518eebb6cb4b49047253d778cb Mon Sep 17 00:00:00 2001 From: freedomprogramer Date: Tue, 13 Jun 2017 18:58:45 +0800 Subject: [PATCH] update load way --- lib/has_magic_fields.rb | 10 +++++++++- lib/has_magic_fields/extend.rb | 14 +++++++------- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/lib/has_magic_fields.rb b/lib/has_magic_fields.rb index b07f3ea..e30f3a9 100644 --- a/lib/has_magic_fields.rb +++ b/lib/has_magic_fields.rb @@ -1,5 +1,13 @@ require "has_magic_fields/version" require "has_magic_fields/extend" - +module HasMagicFields + class Engine < ::Rails::Engine + paths = Dir[File.dirname(__FILE__), '/app/models/**/'] + + if !Rails.env.development? + config.eager_load_paths += paths + end + end +end diff --git a/lib/has_magic_fields/extend.rb b/lib/has_magic_fields/extend.rb index 4819d91..fe1a408 100644 --- a/lib/has_magic_fields/extend.rb +++ b/lib/has_magic_fields/extend.rb @@ -111,14 +111,14 @@ module HasMagicFields end end - - %w{ models }.each do |dir| - path = File.join(File.dirname(__FILE__), '../app', dir) - $LOAD_PATH << path - ActiveSupport::Dependencies.autoload_paths << path - ActiveSupport::Dependencies.autoload_once_paths.delete(path) + if Rails.env.development? + %w{ models }.each do |dir| + path = File.join(File.dirname(__FILE__), '../app', dir) + $LOAD_PATH << path + ActiveSupport::Dependencies.autoload_paths << path + ActiveSupport::Dependencies.autoload_once_paths.delete(path) + end end - end end -- libgit2 0.21.0