This project is archived and is in readonly mode.
Rails.root returns nil before app initialization, silently breaking some gems
-
codesnik
seems that #4009 Move Bundler.require below class Application; end addresses the same issue and has a patch. Still, raising exception could make sense
-
José Valim
- State changed from new to wontfix
If thinking-sphinx requires Rails.root to be set, it needs to create a Rails::Railtie for it and setup the proper initializers. I don't think Rails.root should raise an error. It's ok for it to be nil until it's set.
-
codesnik
thank you. is there any guide for upgrading gems to rails3, where this
change is explicitly stated? And if not an exception, maybe some
deprecation warning would work. If some gem requests Rails.root before
it is set, it is an error, for sure, and it is a pretty common error.
And it could be dangerous.I've managed to spend a half of a hour with debugger trying to
understand what's going on, and still didn't get that I need to create
Rails::Railtie for it. -
macario
Maybe Rails should provide to gems a hook to defer actions after Application is defined. Meanwhile above workaround is not a too bad solution.
-
codesnik
any gem's custom Rails::Railtie subclass provides such a hook.
What I didn't get is how can I fix such a gem, not breaking rails2 compatibility. Maybe check for defined?(Rails::Railtie)..