slackify icon indicating copy to clipboard operation
slackify copied to clipboard

Example in readme throws InvalidHandler exception on startup

Open thisdotrob opened this issue 2 years ago • 1 comments

I've added the RepeatHandler as documented here but (on Rails 7 at least) this gives an exception: repeat_handler is not defined (Slackify::Exceptions::InvalidHandler) ... in 'constantize': uninitialized constant RepeatHandler (NameError).

This is because the Slackify.configure call in config/initializers/slackify.rb is attempting to register the handlers, but they have not been loaded by Rails' autoloader yet.

After reading these docs, I tried using Rails.application.config.to_prepare in config/initializers/slackify.rb:

Rails.application.config.to_prepare do
  Slackify.configure do |config|
    config.slack_bot_token = ...
    config.slack_secret_token = ...
  end
end

This stops the exception on startup, but any changes to the handlers are not loaded until you manually reset the server.

I've also tried adding config.autoload_once_paths << "#{root}/app/handlers" to config/application.rb and again it fixes the startup error but changes to handlers are not loaded without manually resetting.

thisdotrob avatar May 10 '22 14:05 thisdotrob

Hey :wave: on the newer rails versions you now need to load the directory with the handlers. Regarding the reload after file change, this is a known thing that I never got to address. I'll try to implement something using ActiveSupport::FileUpdateChecker

jusleg avatar Jul 07 '22 14:07 jusleg