【发布时间】:2013-05-24 22:02:03
【问题描述】:
这是我所做的:
首先我在app/assets 目录中创建了一个fonts 文件夹。
然后我配置资产管道以识别这个新文件夹。
config/environments/development.rb:
# Add the fonts path
config.assets.paths << Rails.root.join('app', 'assets', 'fonts')
# Precompile additional assets
config.assets.precompile += %w( .svg .eot .woff .ttf .otf )
接下来,我在config/initializers/mime_types.rb中配置mime类型:
# Be sure to restart your server when you modify this file.
# Here are some example that came with the default Rails project.
# Add new mime types for use in respond_to blocks:
# Mime::Type.register "text/richtext", :rtf
# Mime::Type.register_alias "text/html", :iphone
Rack::Mime::MIME_TYPES['.otf'] = 'application/x-font-opentype'
最后,我在我的 SCSS 中引用了字体:
@font-face {
font-family: 'ArnoProDisplay';
src: url('ArnoPro-Display.otf');
font-weight: normal;
font-style: normal;
}
我使用的是谷歌浏览器,控制台显示:
Resource interpreted as Font but transferred with MIME type
application/vnd.oasis.opendocument.formula-template:
"http://localhost:3000/assets/ArnoPro-Display.otf".
我可以在“网络”选项卡中正确看到字体:
【问题讨论】:
标签: ruby-on-rails sass font-face mime-types ruby-on-rails-4