Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding google fonts to Rails application

I'm trying to add google fonts to my Rails 5.2 application and I can't figure out why it doesn't work/what is missing:

i added the following lines in application.scss file :

@import url('://fonts.googleapis.com/css?family=Lato:400,700,900&display=swap');

body {
  padding-top: 70px;
  font-family: 'Lato', sans-serif;
}

Before using @import in application.scss i tried to add in application.html.erb the following line in the head

<link href="https://fonts.googleapis.com/css?family=Lato:400,700,900&display=swap" rel="stylesheet">

Thanks for any help!

like image 650
Agata Avatar asked Nov 10 '19 23:11

Agata


People also ask

How do I add custom fonts to Rails app?

Importing it into my Rails app was pretty easy. First, you create a folder called 'fonts' in your 'assets' folder. After that, you go shopping for fonts! After downloading one that catches your eye, simply drag it to your fonts folder.

Can I use Google Fonts in my app?

Google Fonts is a library of 1455 open source font families and APIs for convenient use via CSS and Android. The library also has delightful and beautifully crafted icons for common actions and items. Download them for use in your digital products for Android, iOS, and web.


1 Answers

It seems the first line in the application.scss, there's a colon ( before //fonts, after url(' ) that causes error. Removing this fixes it:

@import url('//fonts.googleapis.com/css?family=Lato:400,700,900&display=swap');

body {
  padding-top: 70px;
  font-family: 'Lato', sans-serif;
}

No need to add additional line into your application since it'll be compiled in your scss file.

like image 150
ekremkaraca Avatar answered Sep 17 '22 23:09

ekremkaraca