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 Zygmuntowicz
2006-Jan-09 02:50 UTC
[Rails] Question about image storage and relative paths
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 Chen wrote:> 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) > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-Ezra Zygmuntowicz WebMaster Yakima Herald-Republic Newspaper ezra@yakima-herald.com 509-577-7732