导轨 3.1 +资产管道 + webrick 对 /images/ 的请求返回 406
我正在使用 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
试试这个:
background-image: asset-url('image.gif', image);
Try this instead:
background-image: asset-url('image.gif', image);