0

I was working on overriding boiler plate 404 Rails page in RAIlS_ROOT/public. This is Rails 3.1.1 hosted on Pasenger. I noticed that paths in the html document loose context on routes inside a controller resource path in a production environment. This is probably something basic, but wanted to put it out there.

I have

/public /public/404.html
/public/error_stylesheet/styles.css
/public/error_images/image.jpg

404.html has references to the resources

<link href="error_stylesheets/styles.css" rel="stylesheet" type="text/css" />  
<img src="error_images/errorpageheader.jpg">

For example, If I request http://app/wrongurlname My 404.html loads with resources err_stylesheets and err_images folders are seen and retrieved.

If I request http://app/controller/wrong or //app/wrong/wrong The 404 page loads, but can't see the resources.

I was probably not interested in overriding behavior of ApplicationController or routing which seems like it would be necessary to serve erb pages. I'm not sure if serving

cpx
  • 17,009
  • 20
  • 87
  • 142
radlab
  • 53
  • 9

1 Answers1

0

Maybe, you should try this kind of paths:

<link href="/error_stylesheets/styles.css" rel="stylesheet" type="text/css" />  
<img src="/error_images/errorpageheader.jpg">

Without first slash you have relative paths, but with slash you've got an absolute path you need.

Oleksandr Skrypnyk
  • 2,762
  • 1
  • 20
  • 25
  • Thanks, I tried that. Perhaps surprisingly, that doesn't work. But does work. This actually makes sense because it seems like in a 404 or 500 condition, Rails has given up on the request to the HTTP server. – radlab Nov 11 '11 at 21:43
  • And what's happen when you links to `http://yourhost.com/error_stylesheets/styles.css`? – Oleksandr Skrypnyk Nov 11 '11 at 21:46
  • That works. I should say I have this app as sub-site on domain. So I have routes like http://domain/app/route and app is symlinked public folder of a Rails app. – radlab Nov 11 '11 at 21:50