9

I wrote custom instrumentation in my Rails application. I enable it in config/initializers/instrumentation.rbfile like this:

ActiveSupport.on_load(:action_controller) do
  include FooBar::ControllerRuntime
end

But this leads me to errors A copy of FooBar::ControllerRuntime has been removed from the module tree but is still active!. I figure it out that I can resolve it in two ways:

  • Adding path where may 'FooBar::ControllerRuntimeis defined toconfig.autoload_one_paths`
  • Defining :to_prepare callback in ActionController::Railtie

Second solution looks like this:

config.to_prepare do
  ActionController.include FooBar::ControllerRuntime
end

This long introduction leads to question: which way is better? With first I am disabling reloading of classes which lay in the same path as my FooBar::ControllerRuntime. With second I don't feel it is good to messup with ActionController::Railtie. Right know ActionController::Railtie doesn't have defined to_prepare but what happend if in next release it will have?

1 Answer 1

4
+50

The first approach looks cleaner -

Adding path where may 'FooBar::ControllerRuntimeis defined toconfig.autoload_one_paths`

Reasons -

1) If you really wanna do some monkey patches in file like lib/extensions.rb, you may manually require it:

in config/initializers/require.rb:

require "#{Rails.root}/lib/extensions"

2) Follows proper naming conventions as you will have to list down the class and module .

I wouldn't suggest auto-loading for production application though , but if it's the last option than you can certainly try it out .

Good read here on the same - http://www.williambharding.com/blog/technology/rails-3-autoload-modules-and-classes-in-production/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.