ruby-on-rails - 自定义字体在 heroku 中不起作用

标签 ruby-on-rails css heroku ruby-on-rails-4

使用 Rails 4

我已经阅读了很多关于如何让我的自定义字体在 heroku 中工作的主题。它们在开发模式下在本地工作,但是当推送到 heroku 时它们不会出现。

我的@font-face 位于主样式表中

@font-face {
    font-family: 'caviar_dreamsregular';
    src: font-url('caviardreams-webfont.eot');
    src: font-url('caviardreams-webfont.eot?#iefix') format('embedded-opentype'),
         font-url('caviardreams-webfont.woff') format('woff'),
         font-url('caviardreams-webfont.ttf') format('truetype'),
         font-url('caviardreams-webfont.svg#caviar_dreamsregular') format('svg');
    font-weight: normal;
    font-style: normal;

}

应用.rb

config.assets.paths << "#{Rails.root}/app/assets/fonts"

我有预编译 Assets

rake assets:precompile

Heroku 日志中没有错误。

想不通,有人有什么建议吗?

更新:

在我的手机上访问了该网站,字体正常...清除了计算机上的缓存,但仍然无法在计算机上运行。

最佳答案

这可能归结为几个问题;最值得注意的是,我建议您不要使用动态 Assets 路径:


指纹识别

Rails 使用 asset fingerprinting当你预编译 Assets 时

这样做的原因是允许每个 Assets 单独分配给系统,从而提供更稳健的结构(或其他)。基本上,它将 MD5 哈希添加到您的 Assets 文件名的末尾:

global-908e25f4bf641868d8683022a5b62f54.css

路径

因为动态指纹识别使得所有预编译资源有不同的名字,你需要使用 Rails 的动态路径助手:

#app/assets/stylesheets/application.css.scss
@font-face {
    font-family: 'caviar_dreamsregular';
    src: asset-url('caviardreams-webfont.eot');
    src: asset-url('caviardreams-webfont.eot?#iefix') format('embedded-opentype'),
         asset-url('caviardreams-webfont.woff') format('woff'),
         asset-url('caviardreams-webfont.ttf') format('truetype'),
         asset-url('caviardreams-webfont.svg#caviar_dreamsregular') format('svg');
    font-weight: normal;
    font-style: normal;
}

您需要使用动态样式表引擎,例如 SASS处理动态路径

关于ruby-on-rails - 自定义字体在 heroku 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21691846/

相关文章:

mysql - 是否可以将本地 mysql 与 heroku 上的 nodejs 连接?

python - Django heroku 上传文件

heroku - Go 应用程序的依赖项未通过 Heroku 上的 godep 安装

ruby-on-rails - Heroku Puma Rails 4 : Getting R14 errors, 如何扩展我的服务器?

ruby-on-rails - 是否可以覆盖 Rails 路径辅助方法?

html - 父级不会随子级内容缩放

javascript - jquery - 加载功能在 Chrome 中无法正常工作

ruby-on-rails - 如何在 Rails 4 中创建复合主键

ruby-on-rails - Git push Heroku master 需要永远

javascript - 使用 headroom.js