-
-
Notifications
You must be signed in to change notification settings - Fork 231
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Defer modification of ActionController::Base to when it is loaded #250
Defer modification of ActionController::Base to when it is loaded #250
Conversation
The block passed to `ActiveSupport.on_load` is executed with the receiver set to the loaded class.
Seems like a good idea to me, but can you look into the failing travis build and see if it is related to your change? It doesn't seem like it would be, but I don't see those failures in the last couple of commits to master. |
I agree, and it seems like a very good change! We can merge it and release it as soon as the build is green and CHANGELOG entry is added. @cjlarose can u have a look at that? |
I'll take a look and add the changelog entry. Thanks! |
The current version of sprockets is 4.0.0, but the Rails 4.2 app used in the tests is incompatible with that version of sprockets.
The test failures ended up being unrelated to my change, but I fixed it anyway. The most recent build on |
c45d936
to
0c37b8d
Compare
Awesome, thanks for finding/fixing the sprockets issue. |
@@ -23,7 +23,7 @@ def preload | |||
# Development environment should reload settings on every request | |||
if ::Rails.env.development? | |||
initializer :config_reload_on_development do | |||
ActionController::Base.class_eval do | |||
ActiveSupport.on_load :action_controller_base do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you dbl check which version is correct: yours or https://github.com/railsconfig/config/pull/258/files#diff-e1b40370ec751eed3246e103922adc0eR26 ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this version is better. I don't think the class_eval is needed because on_load takes care of it being in the right context.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, that's what I thought too! Then I will merge this one!
Thank you @cjlarose! |
The
railtie
for this gem adds an initializer that loads the classActionController::Base
in order to add abefore_action
to it.The initializer references the
ActionController::Base
constant directly, which, if it isn't alreadyload
ed, will be loaded at that moment.load
ing that class causes other initializers run, including, for example, the initializer defined byactiontext
's engine, as well as various initializers defined by third-party gems in a given application.The effect is that adding the
config
gem to a Rails application that didn't have it causes that application to loadActionController::Base
(and possibly a bunch of related stuff) during initialization, even in contexts where usage ofActionController::Base
isn't expected, like when launching a console throughrails console
.The solution here is to use
ActiveSupport::LazyLoadHooks
to add a hook that runs only after theActionController::Base
has been loaded.