鉴于收到此答案的 cmets(以及不必要的反对票),我已将我的答案修改如下:
Rails 现在似乎已经创建了一种方法来处理资产文件夹中的字体。它是called font-path,工作方式如下:
如果您将自定义字体添加到 /assets/fonts 文件夹,您可以使用
font-path 助手来访问其中的文件。然后可以使用
使用 font-path 助手在您的样式表和其他资产中:
|-app/
|---assets/
|-----fonts/
|-----images/
|-----javascripts/
|-----stylesheets/
@font-face {
font-family:'icofonts';
src:font-url('icofonts.eot');
src:font-url('icofonts.eot?#iefix') format('embedded-opentype'),
...
}
这适用于预编译资产(Heroku 无论如何都会这样做)和静态资产。如果您想要实现此目的的 pre-Rails 4 方式,请参考我的以下回答:
我们在 Heroku 上使用了字体:http://firststop.herokuapp.com(仍在演示中)
这是我们的 CSS:
#assets/application.css
/*-- Akagi Font --*/
@font-face {
font-family: 'akagi';
src: url('fonts/akagi-th-webfont.eot'),
src: url('fonts/akagi-th-webfont.eot?#iefix') format('embedded-opentype'),
url('fonts/akagi-th-webfont.woff') format('woff'),
url('fonts/akagi-th-webfont.ttf') format('truetype'),
url('fonts/akagi-th-webfont.svg#akagithin') format('svg');
font-weight: 300;
font-style: normal;
}
@font-face {
font-family: 'akagi';
src: url('fonts/akagi-bk-webfont.eot');
src: url('fonts/akagi-bk-webfont.eot?#iefix') format('embedded-opentype'),
url('fonts/akagi-bk-webfont.woff') format('woff'),
url('fonts/akagi-bk-webfont.ttf') format('truetype'),
url('fonts/akagi-bk-webfont.svg#akagibook') format('svg');
font-weight: 400;
font-style: normal;
}
@font-face {
font-family: 'akagi';
src: url('fonts/akagi-sb-webfont.eot');
src: url('fonts/akagi-sb-webfont.eot?#iefix') format('embedded-opentype'),
url('fonts/akagi-sb-webfont.woff') format('woff'),
url('fonts/akagi-sb-webfont.ttf') format('truetype'),
url('fonts/akagi-sb-webfont.svg#akagisemibold') format('svg');
font-weight: 500;
font-style: normal;
}
我们将字体放入/stylesheets/fonts folder
我们只是做标准的预编译字体的东西来让所有的 CSS 都在 Heroku 上工作,而且它可以工作。我怀疑你的路径不正确。也许尝试将您的字体目录移动到您的 /assets/stylesheets 文件夹中 :)