Welcome Guest | Login

Can a Rails app "see" files outside it's space?

I have a static website (www.rodneyandtina.com, if it matters) to which I am trying to add some Rails code (under "Our Babies -> Fosters"). What I would like to know is... Can my Rails app, which is in my root folder, at the same level as my website, have access to photos and stylesheets which are in the static website?

So I have a directory structure like this...

public_html
railsapp
www
   images
   stylesheets


Can my railsapp access the 'images' and 'stylesheets' folder in www, and if so, how?  If I understand correctly, Rails looks in its public folder for these directories. So putting something like ../../../www/images in my .rhtml files won't work.

I definitely can't get my stylesheets to work that way. I tried adding
ActionController::Base.asset_host = "rodneyandtina.com" to my environment.rb, but I couldn't get Rails to look anywhere else except its own folders in public.

Thanks,
Tina

2007-08-19 01:18 PM

Hi Tina - lets step back for a sec.  Your file system should look like this (with "->" indicating a symlink)

public_html -> railsapp/public
railsapp
 public
   images
   stylesheets
www -> public_html


since the DocumentRoot of your domain is always public_html, it will thus point to railsapp/public

Now, all rails apps by default have RewriteRules in their public/.htaccess file that tells  apache "hey, if there's a static file, don't send the request into Rails" - that is:

RewriteRule ^$ index.html [QSA]
RewriteRule ^([^.]+)$ $1.html [QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ dispatch.fcgi [QSA,L]


in other words, if the request is not a file in the file system, then send that request to dispatch.fcgi.  

Does that help at all?  Check out our basic deployment tutorial for more information about the setup, or feel free to open a support ticket and have your setup looked at.  Cheers, ~William




2007-08-19 06:39 PM

William, thanks for the response. I still have a lot of confusion about the symlinks (not how to set them up but why), but it seems like what you are telling me is that when a request comes into Apache, it is either "static or Rails" and then the request gets routed appropriately. If that's true, then I would conclude that my Rails app and my static website can never share files (be they images, stylesheets, or otherwise). In other words, the resources that Rails uses must exist within the Rails apps' framework because it really can't "see" anything else.

What I am trying to prevent is having my images and stylesheets (which are shared within my static site and my rails app) in two different places, but from what you're telling me, it seems like this is not possible. Am I correct?

2007-08-19 08:33 PM

Hello,

I guess you will be able to use the images and stylesheets for your rails apps by just by creating a symlinks to the images of your static website. So you needn't  have two copies.  

2007-08-19 09:54 PM

HostingRails Support
Kumar, that worked! I tried it with my images only, but I'm convinced... I'm sure I can get my stylesheets to work, as well. Thank you!

2007-08-19 10:26 PM


Hello Guest! In order to post you must be an active client with us, please log in or sign up today!