Skip to content

Commit

Permalink
Load models from eager_load, not autoload_paths
Browse files Browse the repository at this point in the history
If something is in `autoload_paths`, it doesn't mean it can or should *always* be loaded. Rails explicitly makes this distinction with `eager_load`.

E.g. if I'm developing a Rails engine, I might want to add `lib` to autoload paths (to ease the development of the engine), but that doesn't mean I want to eagerly load ruby files in `lib/generators/templates`!

Resolves #2770
  • Loading branch information
glebm committed Nov 15, 2016
1 parent 9e1c66e commit 517e9a7
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion lib/rails_admin/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ def viable_models
included_models.collect(&:to_s).presence || begin
@@system_models ||= # memoization for tests
([Rails.application] + Rails::Engine.subclasses.collect(&:instance)).flat_map do |app|
(app.paths['app/models'].to_a + app.config.autoload_paths).collect do |load_path|
(app.paths['app/models'].to_a + app.paths.eager_load).collect do |load_path|
Dir.glob(app.root.join(load_path)).collect do |load_dir|
Dir.glob(load_dir + '/**/*.rb').collect do |filename|
# app/models/module/class.rb => module/class.rb => module/class => Module::Class
Expand Down

0 comments on commit 517e9a7

Please sign in to comment.