Elegant way to structure models into subfolders without creating submodules

Here is what I used for Rails 3:

config.autoload_paths += Dir[Rails.root.join('app', 'models', '{**}')]

This configuration tells Rails to scan all the app/models subfolders recursively and load all found models. No namespacing required.


We needed to do this, and there is a very simple way.

move your models into the sub-folders, and then tell rails to load files from all subfolders in your environment.rb file:

config.load_paths += Dir["#{RAILS_ROOT}/app/models/*"].find_all { |f| File.stat(f).directory? }

No namespacing required, and the models can be referred to as normal in your app