Rails 4 public 404/500 错误页面正在请求路径错误的图片资源

Rails 4 public 404/500 error pages are requesting image resources with bad paths

我在我的应用程序的 public 文件夹中构建了一些错误页面(404、500 等)。我知道这些在资产管道之外,所以我将每个构建为一个独立的 html 文件,头部为 CSS。

这些错误页面有几张图片(背景和徽标)。两者都以通常的方式加载(不使用任何 rails 助手):

<img src="Checklick-Logo-White-Transparent.png" alt="Checklick Logo" style="width: 100%">

background: url("Checklick-Cloud-Background-High.jpg") no-repeat center top;

在生产环境中,当我尝试加载这些页面 (app.checklick.com/500.html) 时,它们加载得很好。

但是,当我在应用程序上收到 实际错误 并且加载了相同的错误页面时,出于某种原因,图像路径会附加一个控制器名称(即它们变成 app.checklick.com/programs/Checklick-Logo-White-Transparent.png)。然后控制器尝试使用该图像文件名作为参数执行操作,这会导致另一个错误。当然,浏览器无法呈现任何图像,因此错误页面本身看起来很糟糕。

知道 how/why 控制器名称会在实际错误期间添加到图像请求中吗?

图像应该在 app/assets/images 目录中。

在 public 页面中你可以这样写路径 -

<img src="/assets/Checklick-Logo-White-Transparent.png" alt="Checklick Logo" style="width: 100%">

事实证明,我的 public 404/500 html 页面上的图像没有使用根目录相对路径。

我变了

<img src="Checklick-Logo-White-Transparent.png" alt="Checklick Logo" style="width: 100%">

<img src="/Checklick-Logo-White-Transparent.png" alt="Checklick Logo" style="width: 100%">

并改变

background: url("Checklick-Cloud-Background-High.jpg") no-repeat center top;

background: url("/Checklick-Cloud-Background-High.jpg") no-repeat center top;

现在,无论错误页面的来源是什么,图像都可以正常加载。例如,我可以加载 app.checklick.com/500 或 app.checklick.com/programs/500 并且仍然可以加载图像。