# Links to images keep breaking

**URL:** <https://www.ruby-forum.com/t/links-to-images-keep-breaking/97122>\
**Category:** Rails\
**Created:** [July 5, 2006, 1:46am UTC](https://www.ruby-forum.com/t/links-to-images-keep-breaking/97122 "2006-07-05T01:46:21Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ptremblett](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/dc4da7/32.png) [@ptremblett](https://www.ruby-forum.com/u/ptremblett)\
**Post date:** [July 5, 2006, 1:46am UTC](https://www.ruby-forum.com/t/links-to-images-keep-breaking/97122/1 "2006-07-05T01:46:21Z")

</div>

Hi,

I have a catalog that has images in it. The images are stored in  
public/images/…

When I open the catalog via the catalog controller I get this url:

[http://127.0.0.1:3000/images/sow/sow.jpg](http://127.0.0.1:3000/images/sow/sow.jpg)

for the images and they display correctly.

When I link to the catalog from another controller and view I get this:

[http://127.0.0.1:3000/catalog/images/sow/sow.jpg](http://127.0.0.1:3000/catalog/images/sow/sow.jpg)

If I attempt to put and image in to a view, I get this url:

[http://127.0.0.1:3000/quote/edit/images/sow/sow.jpg](http://127.0.0.1:3000/quote/edit/images/sow/sow.jpg)

To display the images I am using this code: ![]() and the url stored in image\_s is: ‘images/sow/sow.jpg’

Any suggestions on how to sort this out, would be most welcome.

Regards,

Paul

---

<div class="post-metadata">

**Author:** ![ptremblett](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/dc4da7/32.png) [@ptremblett](https://www.ruby-forum.com/u/ptremblett)\
**Post date:** [July 5, 2006, 1:58am UTC](https://www.ruby-forum.com/t/links-to-images-keep-breaking/97122/2 "2006-07-05T01:58:47Z")

</div>

fyi, this has nothing to do with rails, but with the use of relative  
vs absolute URLs and the browser.

since you are using a relative path to the image, your browser is  
attempting to create the absolute path based on the URL of the  
document.

so if you follow a URL such as: [http://www.mysite.com/catalog](http://www.mysite.com/catalog)

and there is an image tag in that document such as

![]()

your browser will actually assume the image’s absolute URL is

[http://www.mysite.com/catalog/images/sow.jpg](http://www.mysite.com/catalog/images/sow.jpg)

so you will want to use a “/” at the beginning of your images src path

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

to indicate to the browser that the images directory starts from the  
root

[http://www.mysite.com/images/sow.jpg](http://www.mysite.com/images/sow.jpg)

instead of

[http://www.mysite.com/catalog/images/sow.jpg](http://www.mysite.com/catalog/images/sow.jpg)

hope this helps.

---

<div class="post-metadata">

**Author:** ![ptremblett](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/dc4da7/32.png) [@ptremblett](https://www.ruby-forum.com/u/ptremblett)\
**Post date:** [July 5, 2006, 3:26am UTC](https://www.ruby-forum.com/t/links-to-images-keep-breaking/97122/3 "2006-07-05T03:26:50Z")

</div>

Thanks Chris, that cleared that one up for me.

Regards,

Paul
