Skip to content

Instantly share code, notes, and snippets.

@ostinelli
Last active July 1, 2018 08:18
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ostinelli/2dccf8c3bed08c74d171d59e5f28495c to your computer and use it in GitHub Desktop.
Save ostinelli/2dccf8c3bed08c74d171d59e5f28495c to your computer and use it in GitHub Desktop.
Reload an initializer file on every request in Rails.
# add this into application.rb
initializer_file = Rails.root.join('config', 'initializers', 'my_initializer.rb')
reloader = ActiveSupport::FileUpdateChecker.new([initializer_file]) do
load initializer_file
end
ActiveSupport::Reloader.to_prepare do
reloader.execute
end
@kokigit
Copy link

kokigit commented Nov 21, 2017

to work this reload_classes_only_on_change should be false

/config/environments/development.rb
config.reload_classes_only_on_change = false

@ostinelli
Copy link
Author

Is this needed for initializers only (purpose of this gist)?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment