2

I want to make a rails application with the 'Mostly Mono' font ("http://www.1001fonts.com/mostlymono-font.html"), and I tried the asset pipeline method the says here Using fonts with Rails asset pipeline .

I placed this in config/application.rb

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

And this to app/assets/stylesheets/application.css

@font-face {
font-family: 'MostlyMono';
src: font-url('/assets/fonts/mostlymono.ttf') format('truetype'); }

Is there any other method or am I doing something wrong?

Community
  • 1
  • 1
Nytz
  • 37
  • 4

1 Answers1

1

You can use custom fonts bellow way -

  1. Create a folder name "fonts" inside the app/assets directory and place mostlymono.ttf fonts inside the fonts directory.
  2. Now add this line to config/application.rb

    config.assets.paths << Rails.root.join("app", "assets", "fonts")
    
  3. Now you have to rename app/assets/stylesheets/application.css to app/assets/stylesheets/application.css.scss and place to bellow code-

    @font-face {
     font-family: "MostlyMono";
     src: url(asset-path("mostlymono.ttf")) format("truetype");
     font-weight: normal;
     font-style: normal;
    }
    
  4. Now add fonts to config/initializers/assets.rb for Precompile additional assets.

    Rails.application.config.assets.precompile += %w( mostlymono.ttf )
    
  • I tried it and it doesn't work, but I got three points: 1.- font-family: "Ionicons" is ok? Shouldn't I put MostlyMono? 2.- I downloaded the font and placed it in app/assets/fonts/, and it's called "mostlymono.medium.tff" 3.- Let's say it works, when I want to use the font I have to put it like .header{ font-family: 'MostlyMono'; } or like .header{ font-family: '@font-face'; } – Nytz Oct 27 '15 at 18:31