# Where are directories

**URL:** <https://www.ruby-forum.com/t/where-are-directories/70913>\
**Category:** Rails\
**Created:** [October 3, 2006, 10:35pm UTC](https://www.ruby-forum.com/t/where-are-directories/70913 "2006-10-03T22:35:19Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![wickie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/ba9def/32.png) [@wickie](https://www.ruby-forum.com/u/wickie)\
**Post date:** [October 3, 2006, 10:35pm UTC](https://www.ruby-forum.com/t/where-are-directories/70913/1 "2006-10-03T22:35:19Z")

</div>

When coding a views/.rhtml file, where do the various directories fall  
in relation to my app. For example, if I have a file in public/images of  
“image1.jpg”, I need to code a “ ![]()” for it (I think, I  
won’t be shocked if someone says "in rails we do it this way). _IF_ I’m  
coding the ![]() tag, where is the file … what directory path do I put  
in so I can find image1.jpg?

Thanks in advance  
—Michel

---

<div class="post-metadata">

**Author:** ![wickie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/ba9def/32.png) [@wickie](https://www.ruby-forum.com/u/wickie)\
**Post date:** [October 3, 2006, 10:58pm UTC](https://www.ruby-forum.com/t/where-are-directories/70913/2 "2006-10-03T22:58:49Z")

</div>

Your web app generally maps to the Rails public folder.

[http://youapp.com/images/image1.jpg](http://youapp.com/images/image1.jpg) =\>  
/railsappname/public/images/image1.jpg

You can make absolute references to your images using  
/images/image\_name.gif from your views. This also applies to  
JavaScripts and stylesheets, which map to /javascripts and /stylesheets  
respectively. Of course you can use relative references, but I’ve found  
the safest bet to be absolute.

---

<div class="post-metadata">

**Author:** ![wickie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/ba9def/32.png) [@wickie](https://www.ruby-forum.com/u/wickie)\
**Post date:** [October 3, 2006, 10:54pm UTC](https://www.ruby-forum.com/t/where-are-directories/70913/3 "2006-10-03T22:54:47Z")

</div>

> When coding a views/.rhtml file, where do the various directories fall  
> in relation to my app. For example, if I have a file in public/images of  
> “image1.jpg”, I need to code a “ ![]()” for it (I think, I  
> won’t be shocked if someone says "in rails we do it this way). _IF_ I’m  
> coding the ![]() tag, where is the file … what directory path do I put  
> in so I can find image1.jpg?

I would just do…

\<%= image\_tag “image1.jpg” %\>

which will result in html similar to:

![](https://www.ruby-forum.com/images/image1.jpg)

Which will look in RAILS\_ROOT/public/images/image1.jpg for that file.

-philip

---

<div class="post-metadata">

**Author:** ![wickie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/ba9def/32.png) [@wickie](https://www.ruby-forum.com/u/wickie)\
**Post date:** [October 3, 2006, 11:05pm UTC](https://www.ruby-forum.com/t/where-are-directories/70913/4 "2006-10-03T23:05:36Z")

</div>

Philip H. wrote:

> \<%= image\_tag “image1.jpg” %\>

I _KNEW_ there’d be a rails way. I looked, but never found that. Thank  
you _VERY_ much.

—Michael

---

<div class="post-metadata">

**Author:** ![wickie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/ba9def/32.png) [@wickie](https://www.ruby-forum.com/u/wickie)\
**Post date:** [October 3, 2006, 11:10pm UTC](https://www.ruby-forum.com/t/where-are-directories/70913/5 "2006-10-03T23:10:51Z")

</div>

Michael S. wrote:

> When coding a views/.rhtml file, where do the various directories fall  
> in relation to my app. For example, if I have a file in public/images of  
> “image1.jpg”, I need to code a “ ![]()” for it (I think, I  
> won’t be shocked if someone says "in rails we do it this way). _IF_ I’m  
> coding the ![]() tag, where is the file … what directory path do I put  
> in so I can find image1.jpg?

As far as your webserver is concerned, the root of your Rails app is  
the ‘public’ directory. So if you have an image called image1.jpg in  
public/images, you can get to it using

![](https://www.ruby-forum.com/images/image1.jpg)

Incidentally, Rails has a built-in image tag helper that assumes that  
images are stored in the /images directory, so in this case you could  
use

\<%= image\_tag(“image1.jpg”) %\>

Chris

---

<div class="post-metadata">

**Author:** ![wickie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/ba9def/32.png) [@wickie](https://www.ruby-forum.com/u/wickie)\
**Post date:** [October 4, 2006, 5:29pm UTC](https://www.ruby-forum.com/t/where-are-directories/70913/6 "2006-10-04T17:29:51Z")

</div>

Chris M. wrote:

> ![](https://www.ruby-forum.com/images/image1.jpg)
> 
> Incidentally, Rails has a built-in image tag helper that assumes that  
> images are stored in the /images directory, so in this case you could  
> use
> 
> \<%= image\_tag(“image1.jpg”) %\>

Thanks, Chris, for both pieces of information. I was really looking for  
the rails helper (I’d guessed it existed but couldn’t find the  
reference), but also wanted to know where things were in case I needed  
them.

Thanks again.  
—Michael
