Rails 4.2:"不应在没有摘要的情况下直接请求资产"

Now*_*ker 0 ruby-on-rails ruby-on-rails-4

在Rails 4.2.0.beta1上我收到一个错误:

如果没有摘要,则不应直接请求资产:使用ActionView :: Helpers中的帮助程序来请求fonts/source-sans-pro.woff

样式表:

@font-face {
  font-family: 'Source Sans Pro';
  font-style: normal;
  font-weight: 400;
  src: local('Source Sans Pro'), local('SourceSansPro-Regular'), url(/assets/source-sans-pro.woff) format('woff');
}
Run Code Online (Sandbox Code Playgroud)

配置是:

config.serve_static_assets = true
config.assets.js_compressor = :uglifier
config.assets.compile = true
config.assets.digest = true
config.assets.version = '1.0'
config.assets.paths << Rails.root.join('app', 'assets', 'fonts')
config.assets.precompile += %w(.svg .eot .woff .ttf)
Run Code Online (Sandbox Code Playgroud)

当然我可以禁用摘要,它可以再次工作,但我有兴趣使用它们.因此,如何在需要时使用摘要source-sans-pro.woff

请注意,我将字体放在assets/fonts目录中,而不是public/目录中.我没有看到图像和字体之间的区别,所以我想将它们保存在同一目录下 - app/assets.

Eye*_*dic 5

使用font_path助手.您必须确保样式表具有此filename.css.scss格式才能生效.

@font-face {
  font-family: 'Source Sans Pro';
  font-style: normal;
  font-weight: 400;
  src: local('Source Sans Pro'), local('SourceSansPro-Regular'), url(font_path('source-sans-pro.woff')) format('woff');
}
Run Code Online (Sandbox Code Playgroud)