# Rails\_root

**URL:** <https://www.ruby-forum.com/t/rails-root/118190>\
**Category:** Rails\
**Created:** [October 24, 2007, 5:14pm UTC](https://www.ruby-forum.com/t/rails-root/118190 "2007-10-24T17:14:54Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![ratschi85](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/77aa72/32.png) [@ratschi85](https://www.ruby-forum.com/u/ratschi85)\
**Post date:** [October 24, 2007, 5:14pm UTC](https://www.ruby-forum.com/t/rails-root/118190/1 "2007-10-24T17:14:54Z")

</div>

Hey,

I’m using the attachment\_fu plugin to upload images on the file system.  
To retrieve them I’m using:

image = “/home/rajeev/Desktop/logo/logo/public#{icon.public\_filename}”  
which is the same as:

“/home/rajeev/Desktop/logo/logo/public/icons/0000/0005/green\_nature\_on\_white.jpg”

Have can i do this in a shorter way by using RAILS\_ROOT? I have tried  
this but no success.

Would appreciate any help.

Thanks

Raj

---

<div class="post-metadata">

**Author:** ![ratschi85](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/77aa72/32.png) [@ratschi85](https://www.ruby-forum.com/u/ratschi85)\
**Post date:** [October 24, 2007, 5:33pm UTC](https://www.ruby-forum.com/t/rails-root/118190/2 "2007-10-24T17:33:08Z")

</div>

On Oct 24, 2007, at 11:14 AM, Rajeev K. wrote:

> green\_nature\_on\_white.jpg"
> 
> Have can i do this in a shorter way by using RAILS\_ROOT? I have tried  
> this but no success.
> 
> Would appreciate any help.
> 
> Thanks
> 
> Raj

Take your pick:

image = File.join(RAILS\_ROOT, “public#{icon.public\_filename}”)  
image = File.expand\_path(‘public’ + icon.public\_filename, RAILS\_ROOT)  
image = File.join(RAILS\_ROOT, ‘public’, icon.public\_filename)

-Rob

Rob B. [http://agileconsultingllc.com](http://agileconsultingllc.com)  
removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![ratschi85](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/77aa72/32.png) [@ratschi85](https://www.ruby-forum.com/u/ratschi85)\
**Post date:** [October 24, 2007, 7:37pm UTC](https://www.ruby-forum.com/t/rails-root/118190/3 "2007-10-24T19:37:51Z")

</div>

> Have can i do this in a shorter way by using RAILS\_ROOT? I have tried  
> this but no success.

just general fyi, but basically the RAILS\_ROOT constant is a String  
object.  
you can use it any way you’d use a string

RAILS\_ROOT + “/some/string/”  
RAILS\_ROOT.split(’/’)  
RAILS\_ROOT.is\_a?(String) # true  
…

hope this helps.  
🙂

---

<div class="post-metadata">

**Author:** ![ratschi85](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/77aa72/32.png) [@ratschi85](https://www.ruby-forum.com/u/ratschi85)\
**Post date:** [October 25, 2007, 10:59am UTC](https://www.ruby-forum.com/t/rails-root/118190/4 "2007-10-25T10:59:14Z")

</div>

Hey,

Thanks for that it works perfect. Just got one question. When I run all  
3 lines in the console i get:

image = File.join(RAILS\_ROOT, ‘public’, icon.public\_filename)  
“script/…/config/…/config/…/public/icons/0000/0005/green\_nature\_on\_white.jpg”

image = File.expand\_path(‘public’ + icon.public\_filename, RAILS\_ROOT)  
“/home/rajeev/Desktop/logo/logo/public/icons/0000/0005/green\_nature\_on\_white.jpg”

image = File.join(RAILS\_ROOT, “public#{icon.public\_filename}”)  
“script/…/config/…/config/…/public/icons/0000/0005/green\_nature\_on\_white.jpg”

Although they all work I don’t understand what the script/…/config…  
bit means?

Cheers

---

<div class="post-metadata">

**Author:** ![ratschi85](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/77aa72/32.png) [@ratschi85](https://www.ruby-forum.com/u/ratschi85)\
**Post date:** [October 25, 2007, 1:14pm UTC](https://www.ruby-forum.com/t/rails-root/118190/5 "2007-10-25T13:14:17Z")

</div>

On Oct 25, 2007, at 4:59 AM, Rajeev K. wrote:

> image = File.expand\_path(‘public’ + icon.public\_filename, RAILS\_ROOT)
> 
> ## Cheers

It means that RAILS\_ROOT == ‘script/…/config/…/config/…’  
It also implies that the current directory is almost certainly the  
same as RAILS\_ROOT because ‘…’ means the parent directory so any  
‘foo/…’ means the foo subdirectory’s parrent – the current  
directory. You can generally remove such constructs (there are some  
oddities that can happen with symbolic links that you can likely  
ignore in this case).

-Rob

Rob B. [http://agileconsultingllc.com](http://agileconsultingllc.com)  
removed\_email\_address@domain.invalid
