Reload every time the file under lib/is reloaded

Memo

TL;DR

config/application.rb


...
config.eager_load_paths += ["#{Rails.root}/lib"]
...

Reference article: https://stackoverflow.com/questions/3282655/ruby-on-rails-3-reload-lib-directory-for-each-request

Deleted because require is no longer needed.

Turn on only in development environment

Since it is done only during development, write as follows to prevent it from being read every time in production.

config/application.rb


...
config.eager_load_paths += ["#{Rails.root}/lib"] if Rails.env.development?
...

Caller


require './lib/invoice_pdf' unless Rails.env.development?

Recommended Posts

Reload every time the file under lib/is reloaded
Read the file under WEB-INF when executing the Servlet