我正在尝试从myfonts.com加载一些webfonts到我在DigitalOcean上运行的rails应用程序中。 它似乎可以进行预编译,并且可以在“开发”模式下本地运行,但不能在“生产”模式下加载文件。
这些问题的其他答案指向资产管道,但解决方案无济于事。
我的文件夹结构如下所示:
app
|assets
||fonts
|||*various font files*
main.scss
@import url("//hello.myfonts.net/count/30b86b");
@font-face {
font-family: 'SofiaProExtraLight';
src: asset-url('30B86B_0_0.eot');
src: asset-url('30B86B_0_0.eot?#iefix') format('embedded-opentype'),asset-url('30B86B_0_0.woff2') format('woff2'),asset-url('30B86B_0_0.woff') format('woff'),asset-url('30B86B_0_0.ttf') format('truetype');
}
@font-face {
font-family: 'SofiaProSemiBold';
src: asset-url('30B86B_1_0.eot');
src: asset-url('30B86B_1_0.eot?#iefix') format('embedded-opentype'),asset-url('30B86B_1_0.woff2') format('woff2'),asset-url('30B86B_1_0.woff') format('woff'),asset-url('30B86B_1_0.ttf') format('truetype');
}
@font-face {
font-family: 'SofiaProRegular';
src: asset-url('30B86B_2_0.eot');
src: asset-url('30B86B_2_0.eot?#iefix') format('embedded-opentype'),asset-url('30B86B_2_0.woff2') format('woff2'),asset-url('30B86B_2_0.woff') format('woff'),asset-url('30B86B_2_0.ttf') format('truetype');
}
只需将其添加到您的application.rb
:
module MyApp
class Application < Rails::Application
# ...
config.assets.paths += %w(fonts)
end
end