# Rails application directory

**URL:** <https://www.ruby-forum.com/t/rails-application-directory/84841>\
**Category:** Rails\
**Created:** [February 8, 2007, 12:41am UTC](https://www.ruby-forum.com/t/rails-application-directory/84841 "2007-02-08T00:41:02Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Diego](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/f04885/32.png) [@Diego](https://www.ruby-forum.com/u/Diego)\
**Post date:** [February 8, 2007, 12:41am UTC](https://www.ruby-forum.com/t/rails-application-directory/84841/1 "2007-02-08T00:41:02Z")

</div>

Hi all,

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?

Cheers,  
Diego

---

<div class="post-metadata">

**Author:** ![Diego](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/f04885/32.png) [@Diego](https://www.ruby-forum.com/u/Diego)\
**Post date:** [February 8, 2007, 12:50am UTC](https://www.ruby-forum.com/t/rails-application-directory/84841/2 "2007-02-08T00:50:03Z")

</div>

I suppose it depends on what context you need the root for. One way  
that always seems to work is to ask for File.dir( **FILE** )

Scott

---

<div class="post-metadata">

**Author:** ![Diego](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/f04885/32.png) [@Diego](https://www.ruby-forum.com/u/Diego)\
**Post date:** [September 25, 2007, 11:01pm UTC](https://www.ruby-forum.com/t/rails-application-directory/84841/3 "2007-09-25T23:01:10Z")

</div>

Sorry. File.dirname( **FILE** )

---

<div class="post-metadata">

**Author:** ![Diego](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/f04885/32.png) [@Diego](https://www.ruby-forum.com/u/Diego)\
**Post date:** [September 25, 2007, 11:09pm UTC](https://www.ruby-forum.com/t/rails-application-directory/84841/4 "2007-09-25T23:09:13Z")

</div>

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
