Links to images keep breaking

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

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

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

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

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

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

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

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

http://www.mysite.com/images/sow.jpg

instead of

http://www.mysite.com/catalog/images/sow.jpg

hope this helps.

Thanks Chris, that cleared that one up for me.

Regards,

Paul

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs