I have a template. In this template i refer to images by using <img src="images/image.gif">. I putted the images in the public/images folder. This works only for the base url, e.g. http://localhost:3000/category. When i make a new category like http://localhost:3000/category/new, the images arent displayed. When i go to the source of the page, and look to the image url it says /images/category/image.gif. Off course, it should be just images/image.gif. Somehow it adds category/ to the image src url. How to prevent Rails from doing this? Thanks in advance! -- Posted via http://www.ruby-forum.com/.
Try making the url "/images/image.gif" (with the leading forward slash) I think that will work, not 100% certain though. Randy On 2/21/06, Ruud Poutsma <ruudjah@gmail.com> wrote:> I have a template. In this template i refer to images by using <img > src="images/image.gif">. I putted the images in the public/images > folder. This works only for the base url, e.g. > http://localhost:3000/category. When i make a new category like > http://localhost:3000/category/new, the images arent displayed. When i > go to the source of the page, and look to the image url it says > /images/category/image.gif. Off course, it should be just > images/image.gif. Somehow it adds category/ to the image src url. How to > prevent Rails from doing this? > Thanks in advance! > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-- Randy Schmidt x@altorg.com 267.334.6833
I had a similar problem recently and Randy is 100% correct. The forward slash will do what you''re looking for. ----- Original Message ----- From: "Randy Schmidt" <x@altorg.com> To: <rails@lists.rubyonrails.org> Sent: Tuesday, February 21, 2006 11:01 AM Subject: Re: [Rails] Images directory Try making the url "/images/image.gif" (with the leading forward slash) I think that will work, not 100% certain though. Randy On 2/21/06, Ruud Poutsma <ruudjah@gmail.com> wrote:> I have a template. In this template i refer to images by using <img > src="images/image.gif">. I putted the images in the public/images > folder. This works only for the base url, e.g. > http://localhost:3000/category. When i make a new category like > http://localhost:3000/category/new, the images arent displayed. When i > go to the source of the page, and look to the image url it says > /images/category/image.gif. Off course, it should be just > images/image.gif. Somehow it adds category/ to the image src url. How to > prevent Rails from doing this? > Thanks in advance! > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-- Randy Schmidt x@altorg.com 267.334.6833 _______________________________________________ Rails mailing list Rails@lists.rubyonrails.org http://lists.rubyonrails.org/mailman/listinfo/rails
> I have a template. In this template i refer to images by using <img > src="images/image.gif">. I putted the images in the public/images > folder. This works only for the base urlInstead of qualifying the path by prepending ''/'', might I also suggest using the image_tag helper: <%= image_tag("close.gif") %> That should continue to work even if you deploy your app to a server that adds an extra path layer.