Rails用错误的MIME类型提供.otf文件.应用程序/ vnd.oasis.opendocument.formula模板

ser*_*erg 3 ruby-on-rails sass font-face mime-types ruby-on-rails-4

这就是我所做的:

首先,我在目录中创建了一个fonts文件夹app/assets.


然后我配置资产管道以识别这个新文件夹.

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 )
Run Code Online (Sandbox Code Playgroud)

接下来,我在下面配置mime类型config/initializers/mime_types.rb:

# 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'
Run Code Online (Sandbox Code Playgroud)

最后,我参考了我的SCSS中的字体:

@font-face {
  font-family: 'ArnoProDisplay';
  src: url('ArnoPro-Display.otf');
  font-weight: normal;
  font-style: normal;
}
Run Code Online (Sandbox Code Playgroud)

我正在使用谷歌浏览器,控制台说:

Resource interpreted as Font but transferred with MIME type
application/vnd.oasis.opendocument.formula-template: 
"http://localhost:3000/assets/ArnoPro-Display.otf".
Run Code Online (Sandbox Code Playgroud)

我可以在"网络"选项卡中正确查看字体:

在此输入图像描述

rai*_*_id 9

更新

解决方案1

更改application/x-font-opentypefont/opentype.来源:字体mime类型

Rack::Mime::MIME_TYPES['.otf'] = 'font/opentype'

并清除缓存

rake tmp:cache:clear
Run Code Online (Sandbox Code Playgroud)

在重新启动服务器之前.


如果解决方案1不起作用,您应该创建文件.htaccess并添加它

AddType application/vnd.oasis.opendocument.formula-template .otf