Monday, February 29, 2016

Using Custom Web Fonts in Rails 4.2.5 Apps


I was getting this error after hooking up Amazon Cloudfront CDN for RubyPlus. Here are the steps to make Rails 4.2.5 use custom fonts.

1. In:

config/application.rb 

config.assets.paths << Rails.root.join("app", "assets", "fonts")

2.  In your .scss files, change the src to use font-url not url:

@font-face {
    font-family: 'icofonts';
    src:font-url('fonts/icofonts.ttf') format('truetype');
    font-weight: normal;
    font-style: normal;
}   
3.  In Moonshine source code, file apache.rb, add 'application/x-font-ttf', 'font/ttf' to the end of the gzip_types:

 defaults = {
    :gzip_types => ['text/html', 'text/plain', 'text/xml', 'text/css', 'text/javascript', 'text/json', 'application/x-javascript', 'application/javascript', 'application/json', 'application/x-font-ttf', 'font/ttf' ]


Reference:

Custom Web Fonts and the Rails Asset Pipeline