且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在 Rails 4 中使用字体

更新时间:2023-02-21 09:48:21

您的 @font-face 声明非常接近,您只是缺少其中的 /assets 前缀网址声明.

Your @font-face declaration is very close, you are just missing the /assets prefix within the url declaration.

@font-face {
    font-family: 'HDVPeace';
    src: url('/assets/HDV_Peace.eot');
    src: url('/assets/HDV_Peace.eot?iefix') format('eot'),
         url('/assets/HDV_Peace.woff') format('woff'),
         url('/assets/HDV_Peace.ttf') format('truetype'),
         url('/assets/HDV_Peace.svg#webfont') format('svg');
}

已添加到 assets.paths 的任何内容都可以直接在开发和生产中的 /assets 路径下使用.您只需要application.rb 中的资产路径修改行,在development.rbproduction.rb 中再做一次只是多余的.

Anything that has been added to assets.paths is available directly under the /assets path in both development and production. You only need the asset path modification line within application.rb, doing it again in development.rb and production.rb is just redundant.

此外,所有字体格式本质上都是二进制的.无需预编译它们,因此您可以安全地删除 assets.precompile 添加.

Additionally, all of the font formats are essentially binary. There is no need to pre-compile them, so you can safely remove the assets.precompile addition.