导轨 3.1 +资产管道 + webrick 对 /images/ 的请求返回 406

发布于 2024-12-17 16:40:48 字数 783 浏览 2 评论 0原文

我正在使用 Rails 3.1 及以下版本的资产管道。

我的图像存储在应用程序/资产/图像中。

在我的 .css.less 文件中,我有:

background-image: url('image.gif');

当编译样式表时,它会按如下方式呈现图像的路径:

background-image: url('/images/image.gif')

当通过 webrick 请求这些图像时,webrick 将为这些请求返回 406 错误代码。手动请求 http://localhost/images/image.gif 也会返回 406。

但是,对 http://localhost/assets/image.gif 的请求仅有效美好的。

当我通过乘客访问rails服务器时,使用/images/image.gif路径可以工作,/assets/image.gif也是如此。

我还尝试将文件更改为 .erb 文件,然后使用 asset_path,得到相同的结果。

我还尝试通过在 .css.less 文件中使用它来手动强制 /assets 路径:

background-image: url('/assets/image.gif')

但这仍然编译 css 文件以使用 /images/image.gif

i'm using the asset pipeline with rails 3.1 and less.

i have my images stored in app/assets/images.

in my .css.less file i have:

background-image: url('image.gif');

when the stylesheet gets compiled, it renders the path to the image as follows:

background-image: url('/images/image.gif')

when these images are requested through webrick, webrick is returning a 406 error code for those requests. manually requesting http://localhost/images/image.gif also returns a 406.

however, a request to http://localhost/assets/image.gif works just fine.

when i access the rails server through passenger, using the /images/image.gif path works, as does /assets/image.gif.

I also tried changing the file to be a .erb file and then using asset_path, with the same results.

I also tried to manually force the /assets path by using this in the .css.less file:

background-image: url('/assets/image.gif')

but that still compiles the css file to use /images/image.gif

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

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

发布评论

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

评论(1

已下线请稍等 2024-12-24 16:40:48

试试这个:

background-image: asset-url('image.gif', image);

Try this instead:

background-image: asset-url('image.gif', image);

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