How to Use Custom Fonts in Rails 4

So I wanted to use the sweet Whitney font in one of my Rails applications. Luckily I had the web font files and proceeded to go on to see how to do this in Rails. Unfortunately, there's nothing out there that explains how to do this correctly. Rest assured that this method works both in development and production.

Place your fonts under vendor/assets/fonts cause that's where they should go. Then within your stylesheets, define your font like so

@font-face {
    font-family: 'Whitney';
    font-weight: normal;
    font-style: normal;
    src: font-url('whitney-book-webfont.eot');
    src: font-url('whitney-book-webfont.eot?iefix') format('eot'),
         font-url('whitney-book-webfont.woff') format('woff'),
         font-url('whitney-book-webfont.ttf') format('truetype'),
         font-url('whitney-book-webfont.svg') format('svg');

Finally, in your config/initializers/assets.rb, you will need the following lines

Rails.application.config.assets.paths << Rails.root.join("vendor", "assets", "fonts")  
Rails.application.config.assets.precompile << /\.(?:svg|eot|woff|ttf)\z/  

That should most definitely work. Tested in 4.2.