【问题标题】:Custom fonts not rendering on heroku in rails自定义字体未在rails中的heroku上呈现
【发布时间】:2014-06-19 14:59:11
【问题描述】:

我能够让字体在 localhost 中工作,但无法让它们在 heroku 上工作。

我已经研究和尝试了很长一段时间,并阅读了几篇文章,但似乎没有任何效果。

以下是所有相关信息:

字体文件

我有一个字体文件 /assets/fonts/MavenProLight-300.otf

CSS

在 application.css.erb 我有

      @font-face {
        font-family: 'maven';
        src:font-url('MavenProLight-300.otf');
        src:url('MavenProLight-300.otf');
        font-weight: normal;
        font-style: normal;
        }

production.rb

在 config/production.rb 我有

  config.assets.paths << Rails.root.join("app", "assets", "fonts")
  config.assets.enabled = true

当我部署到 heroku 本地编译时

  1. RAILS_ENV=production bundle exec rake assets:precompile
  2. git 添加公共/资产
  3. git push heroku master

我猜这行代码是关闭的:

src:font-url('MavenProLight-300.otf');

感谢您的帮助

【问题讨论】:

    标签: ruby-on-rails heroku


    【解决方案1】:

    预编译或使用生产环境只会给我带来更多错误。以下是可行的方法(Rails 6):

    1. this 中所述,将以下内容添加到application.rb(而不是其他任何地方):config.assets.paths &lt;&lt; Rails.root.join("app","assets","fonts")
    2. 在您的 scss 文件中将 src: url('...') 更改为 font-url('...')
    3. git add -Agit commit 的变化
    4. git push 后跟 git push heroku main*
    5. 如果应用程序使用数据库,heroku run rails db:migrate

    *如果弹出关于缺少manifest.json 的错误,请运行rails webpacker:install 并从第3 步重新开始。

    【讨论】:

      【解决方案2】:

      我对@9​​87654321@ 的回答没有什么要补充的,除了记得使用正确的标签来让红宝石启动(.erb 文件

      @font-face {
             font-family: 'maven';
             src: <%= font_url('MavenProLight-300.otf') %>; // ADD THE TAGS
             src: <%= font_url('MavenProLight-300.otf') %>; // ADD THE TAGS
             font-weight: normal;
             font-style: normal;
      }
      

      【讨论】:

        【解决方案3】:

        您是否尝试过使用font_url

         @font-face {
            font-family: 'maven';
            src: font_url('MavenProLight-300.otf');
            src: font_url('MavenProLight-300.otf');
            font-weight: normal;
            font-style: normal;
          }
        

        您的其他步骤似乎是正确的(至少根据我们将应用程序部署到 Heroku 的方式)

        【讨论】:

        • 我正在使用 font-URL 但我只有 URL - 请参见上面的代码。这是我试图让它在本地和 heroku 中工作的尝试。还有其他想法吗?感谢您抽出宝贵时间
        • 没问题!我看到了你的代码 - 我有很多想法,但为了取得更好的进展,你能告诉我你编译的 CSS 中调用该字体的代码吗?我想看看它是如何渲染的
        • 我继续尝试了 font_url ,但仍然没有用。 Heroku 给我回信说我的 .otf 文件可用并正确加载,但我没有正确使用asset_path 帮助程序,所以问题出在其中。在阅读文档后,我希望 font_url 或 font_path 或 asset_path 能够工作,但似乎都没有呈现字体。
        • 我不知道它会从资产路径添加中创建路径名称。 +1
        猜你喜欢
        • 2015-03-28
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-11-04
        相关资源
        最近更新 更多