# Relative paths for images problem

**URL:** <https://www.ruby-forum.com/t/relative-paths-for-images-problem/89694>\
**Category:** Rails\
**Created:** [March 22, 2007, 3:47am UTC](https://www.ruby-forum.com/t/relative-paths-for-images-problem/89694 "2007-03-22T03:47:57Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![zavulon](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/977dab/32.png) [@zavulon](https://www.ruby-forum.com/u/zavulon)\
**Post date:** [March 22, 2007, 3:47am UTC](https://www.ruby-forum.com/t/relative-paths-for-images-problem/89694/1 "2007-03-22T03:47:57Z")

</div>

Hi all,

I have a possibly dumb question.

In my template, I reference the images folder by “…/images/foo.jpg”.  
This works with all my pages that are two levels - i.e. this works for  
example with “…/items/list” page.

However, when I go one level deeper, for example “…/items/show/235”  
page, this doesn’t work, because images need to be referenced by  
“…/…/images/foo.jpg”

Is there a quick and elegant Rails-like solution to this? Can I do  
something like “~/images/foo.jpg” (it has to work both on Windows, where  
I’m developing this, and Linux, where this is going to be deployed)? I  
really don’t want to refer to all images by their absolute path…

Thanks!

---

<div class="post-metadata">

**Author:** ![zavulon](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/977dab/32.png) [@zavulon](https://www.ruby-forum.com/u/zavulon)\
**Post date:** [March 22, 2007, 3:54am UTC](https://www.ruby-forum.com/t/relative-paths-for-images-problem/89694/2 "2007-03-22T03:54:17Z")

</div>

On Mar 21, 2007, at 7:47 PM, zavulon wrote:

> page, this doesn’t work, because images need to be referenced by  
> “…/…/images/foo.jpg”
> 
> Is there a quick and elegant Rails-like solution to this? Can I do  
> something like “~/images/foo.jpg” (it has to work both on Windows,  
> where  
> I’m developing this, and Linux, where this is going to be deployed)? I  
> really don’t want to refer to all images by their absolute path…
> 
> Thanks!

Don’t use relative paths like that. If you just always use a path  
like “/images/foo.jpg” it will work no matter how nested your pages  
are.

Cheers-  
– Ezra Z.  
– Lead Rails Evangelist  
– removed\_email\_address@domain.invalid  
– Engine Y., Serious Rails Hosting  
– (866) 518-YARD (9273)

---

<div class="post-metadata">

**Author:** ![zavulon](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/977dab/32.png) [@zavulon](https://www.ruby-forum.com/u/zavulon)\
**Post date:** [March 22, 2007, 4:02am UTC](https://www.ruby-forum.com/t/relative-paths-for-images-problem/89694/3 "2007-03-22T04:02:28Z")

</div>

Thank you, that works perfectly! I had a suspicion 'twas a stupid  
question…
