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: <img src="<%= li.image_s %>"/> 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 <img src="images/sow.jpg"> 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 <img src="/images/sow.jpg"> 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. On 7/4/06, Paul Jonathan Thompson <rails001@gmail.com> wrote:> 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: <img src="<%= li.image_s > %>"/> 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 > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
Thanks Chris, that cleared that one up for me. Regards, Paul On 05/07/06, Chris Hall <christopher.k.hall@gmail.com> wrote:> 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 > > <img src="images/sow.jpg"> > > 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 > > <img src="/images/sow.jpg"> > > 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. > > On 7/4/06, Paul Jonathan Thompson <rails001@gmail.com> wrote: > > 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: <img src="<%= li.image_s > > %>"/> 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 > > _______________________________________________ > > Rails mailing list > > Rails@lists.rubyonrails.org > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >