1

When I try to load custom fonts in my Rails app, they do not load on the page, and when I inspect them in the source, I get a 404 error. But I'm POSITIVE I've done everything correctly.

CSS:

@font-face {
    font-family: "Roboto";
    src: local(Roboto Thin), url("/assets/fonts/Roboto-Thin.eot");
    src: url("/assets/fonts/Roboto-Thin.eot?#iefix") format("embedded-opentype"), url("/assets/fonts/Roboto-Thin.woff2") format("woff2"), url("/assets/fonts/Roboto-Thin.woff") format("woff"), url("/assets/fonts/Roboto-Thin.ttf") format("truetype");
    font-weight: 200;
}

And my fonts are definitely in /assets/fonts/

Here's how my application.css is laid out:

*= require normalize.css
*= require_tree .
*= require materialize.css

Where materialize.css defines my font files

What else do I need?

jrbedard
  • 3,662
  • 5
  • 30
  • 34
user3183717
  • 4,427
  • 6
  • 20
  • 42
  • 1
    Possible duplicate of [How to use fonts in Rails 4](http://stackoverflow.com/questions/18294150/how-to-use-fonts-in-rails-4) – infused Oct 10 '16 at 23:06

1 Answers1

2

You'll want to use the font_url helper instead of static urls in your CSS.

chad_
  • 3,749
  • 2
  • 22
  • 22
  • I was also able to fix it by adding 'config.assets.paths << Rails.root.join("app", "assets", "fonts")' to my config/application.rb file, but I'm also using Rails 4, not 5. – user3183717 Oct 11 '16 at 00:54
  • That shouldn't really be necessary, using the font_url helper will keep caching working properly, etc. I'd still recommend it. – chad_ Oct 11 '16 at 10:57