将谷歌字体添加到 Rails 应用程序

Aga*_*ata 6 css ruby-on-rails google-font-api

我正在尝试将 google 字体添加到我的 Rails 5.2 应用程序中,但我无法弄清楚为什么它不起作用/缺少什么:

我在 application.scss 文件中添加了以下几行:

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

body {
  padding-top: 70px;
  font-family: 'Lato', sans-serif;
}
Run Code Online (Sandbox Code Playgroud)

在 application.scss 中使用 @import 之前,我尝试在 application.html.erb 头部添加以下行

<link href="https://fonts.googleapis.com/css?family=Lato:400,700,900&display=swap" rel="stylesheet">
Run Code Online (Sandbox Code Playgroud)

谢谢你的帮助!

ekr*_*aca 7

似乎 application.scss 中的第一行,有一个冒号( before //fonts, after url(')导致错误。删除它可以修复它:

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

body {
  padding-top: 70px;
  font-family: 'Lato', sans-serif;
}
Run Code Online (Sandbox Code Playgroud)

无需在您的应用程序中添加额外的行,因为它将在您的 scss 文件中编译。