Tobias Erdle's Blog

Writes mostly about Java, Jakarta EE and software development in general. All views are my own.

Github: erdlet | E-Mail:

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')

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.