Forum: Ruby on Rails Question about image storage and relative paths

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.
Andrew C. (Guest)
on 2006-01-09 04:10
(Received via mailing list)
I'm writing a website with a feature that hosts images that people
upload.

Right now, relative paths works within on my Windows box. So
specifically, I'm able to call File.open on
"public/images/somefile.jpg" and Rails/WEBrick understands that the
path is relative to the home directory of the project. This means that
"public/images/somefile.jpg" ends up referring to the absolute path
"c:\ruby\workspace\SomeProject\public\images\somefile.jpg"

The problem is now I've pushed this out to a Linux box running
Lighty/FastCGI and I get the error Errno::ENOENT with message:

"No such file or directory - public/images/somefile.jpg"

I found that if I prepend the public with the actual path - so,
/usr/local/rails/SomeProject/current/public/images/somefile.jpg" then
the entire setup works.

Any ideas on the best way to approach this?

In particular, a couple ways to fix this:
- Is there a method that returns the home directory of the app?
- Is there a method which complements image_path and tells me the file
system location of where a file should be saved?
- Is there a switch to force Rails to understand relative paths?

Let me know if you guys have any ideas.

Thanks in advance!

Andrew
(from Seattle, WA)
Ezra Z. (Guest)
on 2006-01-09 04:52
(Received via mailing list)
Andrew-

	The constant  RAILS_ROOT always refers to your rails apps root dir.
So just make your paths like this:

RAILS_ROOT/public/foo

Cheers-
-Ezra

On Jan 8, 2006, at 6:09 PM, Andrew C. wrote:

> The problem is now I've pushed this out to a Linux box running
> In particular, a couple ways to fix this:
> (from Seattle, WA)
> _______________________________________________
> Rails mailing list
> removed_email_address@domain.invalid
> http://lists.rubyonrails.org/mailman/listinfo/rails
>

-Ezra Z.
WebMaster
Yakima Herald-Republic Newspaper
removed_email_address@domain.invalid
509-577-7732
This topic is locked and can not be replied to.