【问题标题】:Rails production: Google font imported is not loadedRails 制作:谷歌字体导入未加载
【发布时间】:2015-05-03 17:44:38
【问题描述】:

问题:

在看到有关此主题的问题后,我请求您的帮助。

/assets/stylesheets/styles.css: @import url("http://fonts.googleapis.com/css?family=Merriweather");

当我在 test 或 development 上运行 rails s 时,会加载字体“Merriweather”,但是当我在 production 上运行服务器时,字体没有加载,但是styles.css被加载了。


我尝试过的:

• 将@import url(...) 放入application.css 或welcome.scss 或bootstrap.css.scss

• 将@import url('http://fonts.google...') 更改为@import url('//fonts.google...')

附加信息:

应用程序.css

 *= require_tree .
 *= require_self
 *= require 'styles'

Github: https://github.com/David-Amrani-Hernandez/MovieReader

【问题讨论】:

  • 您的网站在https 协议上运行?
  • @NomanUrRehman 不,正在 http 上运行。我正在使用 Thin,我从 Rails 开始。
  • 尝试在您的项目根目录下运行此命令,然后检查它是否有效。我认为你没有预编译你的资产rake assets:precompile
  • 它不起作用。问题不在于未加载styles.css。问题是加载了styles.css,但没有导入字体。 @NomanUrRehman

标签: css ruby-on-rails fonts import ruby-on-rails-4.2


【解决方案1】:

您是否尝试过直接链接到应用程序布局文件的 <head> 中的字体源,而不是通过样式表?

application.html.erb

<head>
    ...
    <%= stylesheet_link_tag( 'http://fonts.googleapis.com/css?family=Merriweather' ) %>
    ...
</head>

我在生产中多次使用这种方法,它没有给我带来任何问题。我希望你也一样。

【讨论】:

    【解决方案2】:

    虽然@februaryInk 的解决方案有效,但您也可以将@import url(...) 放在application.css.scss 中。但是其他 scss 文件对我不起作用。

    有人对这种有点奇怪的行为有解释吗?导入语句在编译后的application-.css中,但浏览器直接忽略了。

    【讨论】:

      猜你喜欢
      • 2021-12-04
      • 1970-01-01
      • 2013-07-16
      • 2017-01-31
      • 1970-01-01
      • 2013-07-14
      • 2015-09-06
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多