Custom Fonts in Ruby on Rails

Using The Asset Pipeline

This post is mainly for myself so I don’t have to dig through stack overflow responses again if I forget. I just want to quickly jot down adding custom fonts to a Rails project.

1) Add a `fonts` folder to your assets.


2) Add your font files that you want to use into this new folder.
These will be your typical font files (ending in .ttf, .otf, etc)

In your asset/stylesheet section, add @font-face to your primary stylesheet with the font-family and src:


*Update: use `src:font-url()` instead of `src:url()` to avoid issues in production.

3) Then inside of config/initializers/assets add the following with the extension(s) you need (in my case .otf):


Now you should be able to use the imported fonts across your site, by simply assigning the font-family where needed: