I'm trying to reference Rails.root in my application.rb but it is nil, why is that?
I can explain why, but I can't give you a workaround.
Rails.root
is defined in rails/railties/lib/rails.rb
def root
application && application.config.root
end
In application.rb
, the instance of application
is not yet created, because the Application
class is being defined... The application is only initialized after, in environment.rb
:
# Load the rails application
require File.expand_path('../application', __FILE__)
# Initialize the rails application
Testapp::Application.initialize!
EDIT
The workaround is right before our eyes:
my_rails_root = File.expand_path('../..', __FILE__)
Are you using Rails 3.x? If not, you should be using RAILS_ROOT
rather than Rails.root
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With