I want to replace the deprecated RAILS_ROOT with Rails.root as part of the process of getting the application ready to upgrade to Rails 3. The application is currently running with version 2.3.14 and was originally created in 1.2
At the beginning of my boot.rb file is the line:
RAILS_ROOT = "#{File.dirname(FILE)}/.." unless defined?(RAILS_ROOT)
I cant just substitute Rails.root here as Rails is undefined.
What is the recommended way of setting Rails.root?
I dont think I made the question clear enough.
BUT I dont know how to SET Rails.root at startup. I currently appears to be set right at the top of boot.rb with the line:
RAILS_ROOT = "#{File.dirname(FILE)}/.." unless defined?(RAILS_ROOT)
I CANT just change that line to use Rails.root as I will get the error:
../config/boot.rb:3: uninitialized constant Rails (NameError)
Thanks George
You can use like this
Rails.root.join('lib/ca-bundle.crt')
try it
It looks like Rails.root
actually existed in Rails 2.3: http://apidock.com/rails/v2.3.2/Rails/root/class
And in 2.3, it just returns RAILS_ROOT
, so unless I'm mistaken, you can just use Rails.root
in your code without other modifications. When you do the upgrade, your boot.rb
will be replaced, as will the Rails
module, so you code should continue to work properly.
Also, in case you're not using it already, my colleagues and I found this plugin extremely helpful when upgrading from 2.3 to 3.0 a little while back: https://github.com/rails/rails_upgrade
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