1

I have this file structure in my Rails app:

\APP
+---assets
|   +---fonts
|   |       icons.eot
|   |       icons.svg
|   |       icons.ttf
|   |       icons.woff
|   +---icons
|   +---images
|   +---javascripts
|   +---stylesheets
+---controllers
|
... etc ...

The custom font I have (icons) works in development, but not in production (or staging). I know it has something to do with the asset pipeline (404 errors). How do I get my icons / font to show up?

My _icons.scss file (included in application.css.scss):

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

@media screen and (-webkit-min-device-pixel-ratio: 0) {
  @font-face {
    font-family: "icons";
    src: font-url("icons.svg#icons") format("svg");
  }
}

[data-icon]:before {
  content: attr(data-icon);
}

[data-icon]:before,
.icon-ico-addcart:before,
.icon-ico-addcart-hover:before,
.icon-ico-allparsers-menu:before,
.icon-ico-blog-menu:before,
.icon-ico-cart:before,
...

The errors I get:

GET http://127.0.0.1:8888/assets/icons.woff 
GET http://127.0.0.1:8888/assets/icons.ttf 404 (Not Found)      application-e60c1d16b23dd8ae118e0bb3a1d3311c.js:6129 

I am precompiling before. My production environment is my own server. The font was generated using fontcustom with svgs. I used this article to do so.

The font is being precompiled... If I edit the application.css file on the page, changing

url('/assets/icons.woff')

to

url('/assets/icons-8695a8c5b193c6423e0b3b7a9c71b808.woff')

my images appear. This means that my assets are precompiling, but I'm not able to reference them correctly in my scss file.

Jeff
  • 4,285
  • 15
  • 63
  • 115
  • I wrote a generic way to diagnose and solve this problem at http://stackoverflow.com/a/40898227/1197775. – sites Nov 30 '16 at 21:10

2 Answers2

1

What are you using for production? Heroku?

Try precompiling those types of files:

 # In config/initializers/assets.rb
 Rails.application.config.assets.precompile += %w( .ttf ) 

Include all the font endings. You could also try including the font by CDN instead.

If that doesn't work, maybe check out this answer: Rails 4: Why are fonts not loading in production?

builder-7000
  • 7,131
  • 3
  • 19
  • 43
toddmetheny
  • 4,405
  • 1
  • 22
  • 39
  • I am using my own server for prod. Also, the font is one that I compiled myself using [fontcustom](http://thisbythem.com/blog/rails-custom-font-icons/). There is no CDN. It does work in Dev though. – Jeff Sep 01 '15 at 14:31
0

It could be that the content type (application/x-font-woff) isn't served along with the asset, I'd start there.

Andrew
  • 58
  • 5