Fonts in rails assets
In order to use a custom font in a Rails 4 project, you can either put it under public folder (and configure the css path accordingly) or you can load it from assets folder.
First of all, I personally recommend that you read the assets pipeline entry . This will give you a fairly good idea on how to do it.
Nevertheless, given the two options here it goes:
Option 1 – load the font file from the public folder
- Copy the font file to public/fonts/
- configure your css file to load the needed path
- Add the following to your css file
@font-face { font-family: 'VanCondensed'; src:url("/fonts/VanCondensed-Regular.otf"); font-weight: normal; font-style: normal; }
Option 2 – load the font from the assets folder
- Copy the font file to app/assets/fonts/
- Update your config file, so the project knows that it has to load the fonts folder
config.assets.paths << Rails.root.join('app', 'assets', 'fonts')
- configure your css file to load the needed path
- Change the css file extension to css.erb
- Add the following to your css file
@font-face { font-family: 'VanCondensed'; src:url("<%= asset_path('VanCondensed-Regular.otf') %>"); font-weight: normal; font-style: normal; }
- Restart your server