0

In my Rails 5 app, I have this in my application.sass file...

/*
 *= require bootstrap-sass-official
 ...
 */

 @font-face
   font-family: 'Glyphicons Halflings'
   src: url('/assets/glyphicons-halflings-regular.eot')
   src: url('/assets/glyphicons-halflings-regular.eot?#iefix') format('embedded-opentype'), url('/assets/glyphicons-halflings-regular.woff') format('woff'), url('/assets/glyphicons-halflings-regular.ttf') format('truetype'), url('/assets/glyphicons-halflings-regular.svg#glyphicons_halflingsregular') format('svg')

...as per the advice in Ruby on Rails Bootstrap Glyphicons not working. I get this error in my Chrome console: Failed to decode downloaded font: http://localhost:3000/assets/glyphicons-halflings-regular.woff, etc.. for the various font formats.

Do I need to put anything into my Rails assets fonts folder? If so, what specifically? Thanks so much for any help on this.

Community
  • 1
  • 1
Matt
  • 811
  • 2
  • 11
  • 20

1 Answers1

1

As the application is Rails 5, better way - place your fonts in the folder app/assets/fonts.

If you want to place them outside fonts folder, you'll need to add the following configuration:

config.assets.precompile << /\.(?:svg|eot|woff|ttf)\z/

And then can use urls as your mentioned

@font-face {
    font-family: 'Glyphicons Halflings';
    src: url('/assets/glyphicons-halflings-regular.eot');
    src: url('/assets/glyphicons-halflings-regular.eot?iefix') format('eot'),
         url('/assets/glyphicons-halflings-regular.woff') format('woff'),
         url('/assets/glyphicons-halflings-regular.ttf') format('truetype'),
         url('/assets/glyphicons-halflings-regular.svg#glyphicons_halflingsregular') format('svg');
}
idej
  • 5,034
  • 1
  • 11
  • 14
  • @Matt glad to help! The SO thanks - marked as answer answer if it works ;) – idej Apr 20 '17 at 16:17
  • Do you know if there were any differences in Rails 4 in working with glyphicons? – Matt Apr 23 '17 at 01:35
  • 1
    @Matt as I know in rails 4 you don't have font folder but you can create it and update the asset pipeline. Fix is pretty simple. Open your project config file, located at `config/application.rb` and add the following line within your Application class: `config.assets.paths << Rails.root.join("app", "assets", "fonts")` – idej Apr 23 '17 at 23:06