Rails 中的 404 静态错误页面,公共资源的路径上下文根据请求 URI 的变化而变化

发布于 2024-12-14 22:03:26 字数 848 浏览 5 评论 0原文

我正在 RAIlS_ROOT/public 中重写样板 404 Rails 页面。这是 Pasenger 上托管的 Rails 3.1.1。我注意到 html 文档中的路径在生产环境中控制器资源路径内的路由上松散上下文。这可能是一些基本的东西,但想把它放在那里。

我有

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

404.html 引用了资源

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

例如, 如果我请求 http://app/wrongurlname 我的 404.html 加载了资源 err_stylesheets 和 err_images 文件夹,可以看到并检索到。

如果我要求 http://app/controller/wrong 或 //应用程序/错误/错误 404页面加载,但看不到资源。

我可能对覆盖 ApplicationController 或路由的行为不感兴趣,这似乎有必要为 erb 页面提供服务。我不确定是否提供服务

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

滥情哥ㄟ 2024-12-21 22:03:26

也许,您应该尝试这种路径:

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

如果没有第一个斜杠,您将拥有相对路径,但使用斜杠您将获得所需的绝对路径。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文