【问题标题】:rails: font don't appear in productionrails:字体不会出现在生产中
【发布时间】:2016-05-30 16:58:10
【问题描述】:

我在我的 ruby​​ on rails 应用程序中使用 Montserrat 字体。在我的桌面上出现了字体,但我在其他电脑上检查过,它是新罗马时代的。

我在 application.rb 中添加了这个:

config.assets.paths << Rails.root.join("app", "assets", "fonts")
config.assets.precompile << /\.(?:svg|eot|woff|ttf)$/

我的字体在 assets/fonts/montserrat:

这是我的 font.scss

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

我这样称呼字体:

.welcome{
  font-family: 'Montserrat';
  color: #333;
  text-align: center;
}

我做错了什么?

【问题讨论】:

  • 旁注:如果您使用的是 WOFF,则不需要 ttf/otf; SVG 字体已被废弃,因为它们很糟糕,eot 已被 WOFF 弃用,因此您不需要所有这些不同的格式(幸好不再是 2012 年),只需使用 WOFF 并降低复杂性。有关详细信息,请参阅stackoverflow.com/a/37091681/740553
  • 我只需要 woff url 吗?
  • 至少在支持当前的web方面,你只需要WOFF资源,其他的不需要。然后在你的scss 中你只需要 woff 的 url。
  • 我已删除,但无法正常工作
  • 我知道,我并不是要解决你的问题,只是解释一下,今天你不需要所有这些字体格式,只需要一种格式。

标签: css ruby-on-rails fonts


【解决方案1】:

您必须运行 bundle exec rake assets:precompile RAILS_ENV=production 然后执行 git add/git commit 然后将新提交推送到您的生产环境。

【讨论】:

    猜你喜欢
    • 2013-11-12
    • 2015-10-30
    • 1970-01-01
    • 1970-01-01
    • 2013-09-04
    • 1970-01-01
    • 2014-09-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多