Skip to content

Commit ead1775

Browse files
authored
Merge pull request #2771 from glebm/patch-1
Load models from eager_load, not autoload_paths
2 parents 7873770 + dd3e4fc commit ead1775

3 files changed

Lines changed: 6 additions & 2 deletions

File tree

lib/rails_admin/config.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ def viable_models
323323
included_models.collect(&:to_s).presence || begin
324324
@@system_models ||= # memoization for tests
325325
([Rails.application] + Rails::Engine.subclasses.collect(&:instance)).flat_map do |app|
326-
(app.paths['app/models'].to_a + app.config.autoload_paths).collect do |load_path|
326+
(app.paths['app/models'].to_a + app.paths.eager_load).collect do |load_path|
327327
Dir.glob(app.root.join(load_path)).collect do |load_dir|
328328
Dir.glob(load_dir + '/**/*.rb').collect do |filename|
329329
# app/models/module/class.rb => module/class.rb => module/class => Module::Class

spec/dummy_app/config/application.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class Application < Rails::Application
2020
# Application configuration should go into files in config/initializers
2121
# -- all .rb files in that directory are automatically loaded.
2222
config.eager_load_paths.reject! { |p| p =~ %r{/app/(\w+)$} && !%w(controllers helpers views).push(CI_ORM).include?(Regexp.last_match[1]) }
23-
config.autoload_paths += %W(#{config.root}/app/#{CI_ORM} #{config.root}/app/#{CI_ORM}/concerns)
23+
config.autoload_paths += %W(#{config.root}/app/#{CI_ORM} #{config.root}/app/#{CI_ORM}/concerns #{config.root}/lib)
2424
config.i18n.load_path += Dir[Rails.root.join('app', 'locales', '*.{rb,yml}').to_s]
2525
config.active_record.raise_in_transactional_callbacks = true if Rails::VERSION::MAJOR == 4 && Rails::VERSION::MINOR == 2 && CI_ORM == :active_record
2626
config.active_record.time_zone_aware_types = [:datetime, :time] if Rails::VERSION::MAJOR >= 5 && CI_ORM == :active_record
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module DoesNotLoadAutoloadPathsNotInEagerLoad
2+
raise 'This file is in app.paths.autoload but not app.paths.eager_load and ' \
3+
' should not be autoloaded by rails_admin'
4+
end

0 commit comments

Comments
 (0)