【发布时间】:2014-07-14 07:43:38
【问题描述】:
目前我正在尝试将自定义字体添加到我的 Rails 4 应用程序中。
- 我将所有字体添加到
assets/fonts - 我将
config.assets.paths << Rails.root.join("app", "assets", "fonts")添加到config/application.rb - 我将脚本添加到我的
style.css
@font-face {
font-family: 'oxygenregular';
src: url(font-path('oxygen-regular-webfont.eot') + "?#iefix") format('embedded-opentype'),
url(font-path('oxygen-regular-webfont.woff')) format('woff'),
url(font-path('oxygen-regular-webfont.ttf')) format('truetype'),
url(font-path('oxygen-regular-webfont.svg') + "#MyFont") format('svg');
}
body {
font-family: 'oxygenregular', arial;
background: #f4f5f9;
background-image: url(../images/bg-pattern.png);
background-position: 0 bottom;
background-repeat: no-repeat;
}
我没有收到像404 (Not Found) 这样的错误,因为我在修改config/application.rb 之前收到了错误
但是应用程序没有加载我已经放置的字体。我尝试使用原生 HTML,字体运行良好,但是当我尝试将它们放入 Rails 应用程序时,它不会加载。a
【问题讨论】:
-
子问题:
Rails.application.config.assets.precompile << /\.(?:svg|eot|woff|ttf)\z/做够了吗,还是还需要加路径?
标签: ruby-on-rails fonts font-face