Rails 4:为什么字体不能在生产中加载? [英] Rails 4: Why are fonts not loading in production?

查看:141
本文介绍了Rails 4:为什么字体不能在生产中加载?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

无法在生产中的Rails 4应用程序中加载字体,它在开发过程中正常工作。
$ b 资源在部署时在服务器上预编译。



我的字体是
$ b $ p $ app / assets / fonts



我的app.css:

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



$ b $在我的production.rb中我有:

  config.assets.precompile<< Proc.new {| path | 
if path =〜/\.(eot|svg|ttf|woff)\z/
true
end
}


解决方案

上周我们有这个问题 - 问题是您的资产将被编译为MD5散列他们,而你的标准CSS仍然在寻找他们的标准名称。这是图像和图像的问题。字体。

  @ font-face {
font-family:'akagi';
src:asset_url('fonts / akagi-th-webfont.eot');
src:asset_url('fonts / akagi-th-webfont.eot?#iefix')format('embedded-opentype'),
asset_url('fonts / akagi-th-webfont.woff') format('woff'),
asset_url('fonts / akagi-th-webfont.ttf')format('truetype'),
asset_url('fonts / akagi-th-webfont.svg#akagithin ')格式('svg');
font-weight:300;
font-style:normal;



$ b $ p
$ b

这是一个如何使用scss 文件来动态加载资源。这些文件被编译(无论是在推送之前或在初始化过程中)到您的.css文件,所有文件的资产正确同步。

我们有一个类似的问题与你Heroku,并设法通过将我们的文件放入/stylesheets/layout/fonts.css.scss,然后调用

  @import '/布局/字体'; 

我们也调用了我们的application.css - > application.css.scss来支持@import函数


I can't load fonts in my Rails 4 app in production, it works normally in development.

Assets are precompiled on the server while deploying.

I have my fonts in

app/assets/fonts

My app.css:

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

In my production.rb I have:

config.assets.precompile << Proc.new { |path|
  if path =~ /\.(eot|svg|ttf|woff)\z/
    true
  end
}

解决方案

We had this problem last week - the problem is that your assets will be compiled to have MD5 hashes on them, whilst your standard CSS will still be looking for their "standard" names. This is a problem with images & fonts.

@font-face {
    font-family: 'akagi';
    src: asset_url('fonts/akagi-th-webfont.eot');
    src: asset_url('fonts/akagi-th-webfont.eot?#iefix') format('embedded-opentype'),
         asset_url('fonts/akagi-th-webfont.woff') format('woff'),
         asset_url('fonts/akagi-th-webfont.ttf') format('truetype'),
         asset_url('fonts/akagi-th-webfont.svg#akagithin') format('svg');
    font-weight: 300;
    font-style: normal;
}

This is an example of how you should use scss files to load assets dynamically. These files are compiled (either before push or during init) into your .css files, all with their assets correctly synced.

We had a similar problem to you with Heroku, and managed to get it working by putting our files into /stylesheets/layout/fonts.css.scss and then calling

@import '/layout/fonts';

We also called our application.css -> application.css.scss to support the @import function

这篇关于Rails 4:为什么字体不能在生产中加载?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆