Member-only story
Using Subfolders In Rails To Better Organize Models For Single Table Inheritance
This strategy can help organize your Rails models into subfolders making it more readable plus a lot cleaner when using single table inheritance.
One of the things I love about Rails, is its convention over configuration philosophy. Things just work out of the box, however Rails still provides the ability to customize when needed.
One of the patterns I like to follow, is putting all my models, jobs and mailers into subfolders. This helps create a better folder structure for your classes, plus also works great when using single table inheritance.
Add AutoloadPaths
For Rails to automatically load models, jobs or mailers in subfolders, you need to add the following to you config/application.rb file.
config.autoload_paths += Dir[Rails.root.join('app', 'jobs', '**/')]
config.autoload_paths += Dir[Rails.root.join('app', 'models', '**/')]
config.autoload_paths += Dir[Rails.root.join('app', 'mailers', '**/')]
Now Rails will automatically load files all these subfolders. This gives you flexibility to structure classes in subfolders without worrying about whether they are loaded or not.