I am having trouble figuring out the "right" way to specify the path to an image when it is an attribute of something other than an image tag. For example, I see that image_tag("myimage.png") automatically knows to look in the public/images directory. How do I accomplish the same thing for other tags? For example, my layout has: <td background="menu_bg.gif" width="1"> Also, in my css file: tr#logobar { background-image:url("logo_bg.gif") } In these cases it seems that specifying the image name is not enough. First, I tried a relative path ("images/logo_bg.gif") but this failed. A full path worked ("/images/logo_bg.gif") worked, but this causes problems for deployment. My server has the application root in a subdirectory. In other words, my application is in: http://my.server.com/myapp All of the places where I had "/images/logo_bg.gif" fail on the server. I have to manually change them to "/myapp/logo_bg.gif" for them to work. It doesn''t seem like manually updating those links every time I want to deploy a new version is the right way to do this. What am I missing here? --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Serengeti wrote:> First, I tried a relative path ("images/logo_bg.gif") but this failed.Image references in CSS should be done relative to the document containing the css. So if you have a stylesheet in the standard Rails stylesheets directory, images should be... ../images/foo.jpg I''d avoid putting image-referencing style data in your layouts, save this for stylesheets, it saves a *lot* of hassle when working out paths, especially if your routing configuration ever changes. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Thanks for the advice. I did as you suggested and everything appears to work fine. FYI to any other newbies out there like me -- be sure to budget as much time for deploying from your development machine to your production machine as you spent writing your application (more, if your application is pretty simple). I suspect that this is a one-time problem. Once I get my first app up- and-running I suspect deploying additional apps will be easy. On Jun 7, 7:21 am, Douglas Shearer <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> Serengeti wrote: > > First, I tried a relative path ("images/logo_bg.gif") but this failed. > > Image references in CSS should be done relative to the document > containing the css. So if you have a stylesheet in the standard Rails > stylesheets directory, images should be... > > ../images/foo.jpg > > I''d avoid putting image-referencing style data in your layouts, save > this for stylesheets, it saves a *lot* of hassle when working out paths, > especially if your routing configuration ever changes. > > -- > Posted viahttp://www.ruby-forum.com/.--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---