简体   繁体   English

Rails资产管道:找不到字体

[英]Rails asset pipeline: fonts not found

I have a strange error, where some fonts are found but some aren't. 我有一个奇怪的错误,其中一些字体被发现,但有些不是。 Basically I have two fonts font1 (custom font from IconMoon) and Brandon (from fonts.com). 基本上我有两种字体font1 (从IconMoon自定义字体)和Brandon (从fonts.com)。 My directory structure is 我的目录结构是

- app
  - assets
    - fonts
      - font1.eot
      - ...
      - 172fdde2-f56b-433a-a6e2-ebeab9dfb588.eot
      - ...

I'm using SCSS to load my fonts: 我正在使用SCSS加载我的字体:

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

@font-face{
  font-family:'Brandon Grot W01 Medium';
  src:font-url('172fdde2-f56b-433a-a6e2-ebeab9dfb588.eot?#iefix');
  src:font-url('172fdde2-f56b-433a-a6e2-ebeab9dfb588.eot?#iefix') format('eot'),
  font-path('50ca6f6f-b64d-4af0-9b30-526cf363d87e.woff2') format('woff2'),
  font-url('050c2cbf-b818-4b8e-b6d2-71b70478bd9d.woff') format('woff'),
  font-url('7da41ce3-b3fd-4fca-a85f-4f3099884c15.ttf') format('truetype'),
  font-url('37c88f3d-9532-4547-9e11-7cca7f66048c.svg#37c88f3d-9532-4547-9e11-7cca7f66048c') format('svg');
}

When I try to load the font1 fonts, everything works. 当我尝试加载font1字体时,一切正常。 But when I try to load the Brandon font I get 404 errors. 但是当我尝试加载Brandon字体时,我得到了404错误。 This is the generated CSS: 这是生成的CSS:

@font-face {
  font-family: 'font1';
  src: url(/assets/font1.eot?-kpzpl9);
  src: url(/assets/font1.eot?#iefix-kpzpl9) format("embedded-opentype"), url(/assets/font1.woff?-kpzpl9) format("woff"), url(/assets/font1.ttf?-kpzpl9) format("truetype"), url(/assets/font1.svg?-kpzpl9#font1) format("svg");
  font-weight: normal;
  font-style: normal;
}

@font-face {
  font-family: 'Brandon Grot W01 Medium';
  src: url(/assets/172fdde2-f56b-433a-a6e2-ebeab9dfb588.eot?#iefix);
  src: url(/assets/172fdde2-f56b-433a-a6e2-ebeab9dfb588.eot?#iefix) format("eot"), "/assets/50ca6f6f-b64d-4af0-9b30-526cf363d87e.woff2" format("woff2"), url(/assets/050c2cbf-b818-4b8e-b6d2-71b70478bd9d.woff) format("woff"), url(/assets/7da41ce3-b3fd-4fca-a85f-4f3099884c15.ttf) format("truetype"), url(/assets/37c88f3d-9532-4547-9e11-7cca7f66048c.svg#37c88f3d-9532-4547-9e11-7cca7f66048c) format("svg");
}

Calls to /assets/font1.eot result in a 200 and calls to /assets/172fdde2-f56b-433a-a6e2-ebeab9dfb588.eot result in a 404 . 调用/assets/font1.eot产生200并调用/assets/172fdde2-f56b-433a-a6e2-ebeab9dfb588.eot得到404

I'm not sure why this happens, because they are in the same directory. 我不确定为什么会这样,因为它们在同一个目录中。 The logs look like this 日志看起来像这样

Started GET "/assets/font1.eot" for 127.0.0.1 at 2016-02-05 10:38:22 +0100
Served asset /font1.eot - 304 Not Modified (0ms)

Started GET "/assets/172fdde2-f56b-433a-a6e2-ebeab9dfb588.eot" for 127.0.0.1 at 2016-02-05 10:39:25 +0100
Served asset /172fdde2-f56b-433a-a6e2-ebeab9dfb588.eot - 404 Not Found (6ms)

I'm on Rails 3.2.9 我在Rails 3.2.9上

Any ideas on how to debug this issue? 有关如何调试此问题的任何想法?

The problem is caused by the hyphens in the name. 问题是由名称中的连字符引起的。

If you rename your files to use underscores instead, for example 172fdde2_f56b_433a_a6e2_ebeab9dfb588.eot , and then replace the hyphens with underscores in your css files, everything should work. 如果您将文件重命名为使用下划线,例如172fdde2_f56b_433a_a6e2_ebeab9dfb588.eot ,然后在css文件中用下划线替换连字符,则一切都应该有效。

It's caused by sprockets trying to strip out fingerprints when resolving the asset. 这是由链轮试图在解析资产时剥离指纹引起的。 Ultimately it strips out part or all of the filename and then finds no matching file. 最终它会删除部分或全部文件名,然后找不到匹配的文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM