下载 Web 字体时 Rails 3.1 错误 406 响应
我在使用指南针的 Spree 0.70 应用程序中通过 Rails 3.1 提供 Web 字体时遇到问题(我认为这不会产生影响)
我有一个包含声明的 scss 文件:
@font-face {
font-family: 'RokkittRegular';
src: font_url('fonts/store/rokkitt-font/Rokkitt-webfont.eot');
src: local('Rokkitt Regular'),
font_url('fonts/store/rokkitt-font/Rokkitt-webfont.eot?#iefix') format('embedded-opentype'),
font_url('fonts/store/rokkitt-font/Rokkitt-webfont.woff') format('woff'),
font_url('fonts/store/rokkitt-font/Rokkitt-webfont.ttf') format('truetype'),
font_url('fonts/store/rokkitt-font/Rokkitt-webfont.svg#RokkittRegular') format('svg');
font-weight: normal;
font-style: normal;
}
这些声明已成功包含在输出的 css 中,字体文件本身存储在:
/app/assets/fonts/store/rokkitt-font/
并包含:
- Rokkitt-webfont.eot
- Rokkitt-webfont.svg
- Rokkitt-webfont.ttf
- Rokkitt-webfont.woff
但是当我访问该网站时,字体没有呈现。我尝试直接访问这些文件,但没有得到响应。我本希望浏览器尝试下载该文件,但我得到的只是错误 406 响应。样式表中的其他资源(例如图像)可以正确渲染。谁能帮我诊断一下这个问题吗?我想这可能与哑剧类型有关,尽管我不确定。
提前致谢
I'm having problems serving web fonts through Rails 3.1, within a Spree 0.70 application using compass (which I don't think should make a difference)
I have a scss file which contains the declarations:
@font-face {
font-family: 'RokkittRegular';
src: font_url('fonts/store/rokkitt-font/Rokkitt-webfont.eot');
src: local('Rokkitt Regular'),
font_url('fonts/store/rokkitt-font/Rokkitt-webfont.eot?#iefix') format('embedded-opentype'),
font_url('fonts/store/rokkitt-font/Rokkitt-webfont.woff') format('woff'),
font_url('fonts/store/rokkitt-font/Rokkitt-webfont.ttf') format('truetype'),
font_url('fonts/store/rokkitt-font/Rokkitt-webfont.svg#RokkittRegular') format('svg');
font-weight: normal;
font-style: normal;
}
These declarations are successfully included in the outputted css, and the font files themselves are stored in:
/app/assets/fonts/store/rokkitt-font/
and contain:
- Rokkitt-webfont.eot
- Rokkitt-webfont.svg
- Rokkitt-webfont.ttf
- Rokkitt-webfont.woff
But when i visit the site the fonts aren't rendered. I've tried visiting the files directly and I don't get a response. I would've expected the browser to try and download the file, but instead all I get is an error 406 response. Other assets in the stylesheets, such as images render correctly. Can anyone help me diagnose this? I was thinking it might be something to do with Mime-types, although I'm not sure.
Thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当您使用 font_url 或其他 Rails 3.1 资源助手时,您不需要在 url 中添加资源类型(在本例中为:“字体”)。所以网址应该是:
这解决了问题。希望这对遇到此问题的其他人有所帮助。
我猜我还在习惯资产管道……把这记作一个小学生的错误!
When you use font_url or other rails 3.1 asset helpers you don't need the asset type - in this case: 'fonts' - in the url. So the urls should have been:
Which solves the problem. Hope this helps anyone else who comes across this problem.
Guess i'm still getting used to the asset pipeline... chalk this one up as a school boy mistake!