I was wondering if there was a kosher way of getting the complete path
to the root location of a Rails app? I know there’s ROOT_PATH, but I
think that changes when I do Dir.chdir() to some other location. Or at
least it’s what I am seeing.
For example:
Dir.pwd
=> “/Users/diego/Code/Rails/mview”
puts RAILS_ROOT
script/…/config/…/config/…
=> nil
Dir.chdir(’/’)
=> 0
puts RAILS_ROOT
script/…/config/…/config/…
=> nil
Dir.pwd
=> “/”
So basically anytime I do a chdir, away from the Rails root dir, I can
no longer use RAILS_ROOT to get a starting point to do file and
directory work.
Do I just need to define a global const with my app’s complete path
and use that?
Thanks, Scott. I want the root as a starting point from which I can
(for example) store uploaded files somewhere in my application’s
directory structure. I may want to get to:
/Users/diego/MyApp/public/data/images
So I wanted to have a way to always get /Users/diego/MyApp/ and I can
go off from there.
Thanks for the tip on using FILE. What I did, before your reply,
was to add APP_ROOT = File.expand_path(RAILS_ROOT) in the
application’s initialization.
Diego
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.