Saturday, April 11, 2015

Using Custom Fonts in Rails 4.2

1. For Rails 4.2, copy the custom fonts to the folder app/assets/fonts. I am using the purchased fonts OpenSans.

2. Declare your font in your css file like this:

@font-face {
    font-family: 'OpenSans-Bold';
    src:url('OpenSans-Bold.ttf');
}

3. Use the declared font in css. For example:

font-family: 'OpenSans-Regular'

4. Add gem 'font-awesome-sass' to Gemfile

5. Run bundle intall

6. In application.scss, add:

@import "font-awesome-sprockets";
@import "font-awesome";