views:

107

answers:

3

I recently migrated my application across servers and set up my directories a little.

I ran into a problem where I had hard coded some paths, in particular, where I store all my attachments.

I moved my attachment directory in app_path/../attachments/*

Is there a variable that gets me my app_path, rails root directory, or whatever the correct term for it is?

And this variable needs to be accessible from controllers and models.

Thanks

+1  A: 

Either: RAILS_ROOT or Rails.root

captaintokyo
RAILS_ROOT in rails2, Rails.root in rails3
Yannis
In 2.3.8 `Rails.root` also works... don't know about lower versions.
captaintokyo
+1  A: 

Hi, You can access rails app path using variable RAILS_ROOT.

For example, render :file => ”#{RAILS_ROOT}/public/layouts/mylayout.html.erb”

Thanks, Anubhaw

Anubhaw
+1  A: 

For super correctness, you should use:

Rails.root.join('foo','bar')

which will allow your app to work on platforms where / is not the directory separator, should anyone try and run it on one.

malclocke