Tobias Erdle's Blog

Development Engineer working with different technologies. Former Jakarta MVC & Eclipse Krazo Committer. All views are my own.

Github: erdlet | E-Mail: blog (at) erdlet (punkt) de

Load Rails /lib subdirectories in production

When I add code to my app which I may want to extract later, I like to place it within RAILS_ROOT/lib inside some subdirectory like /logging. To get the content of those directories loaded, the config/application.rb needs to be extended like this:

class Application < Rails::Application
   ...

  config.eager_load_paths << Rails.root.join('/lib/logging')
end

With this setting enabled, the application will recognize the classes when loaded with config.eager_load = true, which is used most of the time in staging and production environments.