Forum: Ruby on Rails Relative paths for images problem

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
zavulon (Guest)
on 2007-03-22 04:47
Hi all,

I have a possibly dumb question.

In my template, I reference the images folder by "../images/foo.jpg".
This works with all my pages that are two levels - i.e. this works for
example with "../items/list" page.

However, when I go one level deeper, for example "../items/show/235"
page, this doesn't work, because images need to be referenced by
"../../images/foo.jpg"

Is there a quick and elegant Rails-like solution to this? Can I do
something like "~/images/foo.jpg" (it has to work both on Windows, where
I'm developing this, and Linux, where this is going to be deployed)? I
really don't want to refer to all images by their absolute path...

Thanks!
Ezra Z. (Guest)
on 2007-03-22 04:54
(Received via mailing list)
On Mar 21, 2007, at 7:47 PM, zavulon wrote:

> page, this doesn't work, because images need to be referenced by
> "../../images/foo.jpg"
>
> Is there a quick and elegant Rails-like solution to this? Can I do
> something like "~/images/foo.jpg" (it has to work both on Windows,
> where
> I'm developing this, and Linux, where this is going to be deployed)? I
> really don't want to refer to all images by their absolute path...
>
> Thanks!
>

  Don't use relative paths like that. If you just always use a path
like "/images/foo.jpg"  it will work no matter how nested your pages
are.

Cheers-
-- Ezra Z.
-- Lead Rails Evangelist
-- removed_email_address@domain.invalid
-- Engine Y., Serious Rails Hosting
-- (866) 518-YARD (9273)
zavulon (Guest)
on 2007-03-22 05:02
Thank you, that works perfectly! I had a suspicion 'twas a stupid
question...
This topic is locked and can not be replied to.