【问题标题】:CSS Background Images Not Showing in HerokuCSS 背景图像未在 Heroku 中显示
【发布时间】:2016-09-17 04:59:46
【问题描述】:

我在 SO 和其他帮助网站上阅读了大量关于此问题的帖子,但到目前为止没有任何帮助。我的 CSS 中有图像显示在我的 localhost 上,但当我将应用程序推送到 Heroku 时却没有。

这是一个图像示例:

.hero-000 {
    width: 102%;
    background: url(hero-000.jpg) no-repeat center center fixed;
    -webkit-background-size: cover;
    -moz-background-size: cover;
    -o-background-size: cover;
    background-size: cover;
}

根据其他帖子的建议,我已将此添加到我的application.rb

config.assets.initialize_on_precompile = false

我也将此添加到我的production.rb

  config.serve_static_files = true
  config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect'
  config.assets.compile = true
  config.assets.digest = true

我按照 Heroku 网站上的步骤预编译资产 here

我真的不知道从哪里开始,所以非常感谢任何帮助。

【问题讨论】:

  • 在 css 中像这样指定图像路径: background-image: image-url("hero-000.jpg")
  • hero-000.jpg文件在哪里?
  • @PardeepSaini 这样做会使图像在我的localhost 上消失。而@uzaif 图像在app/assets/images/ 中,但由于我尝试预编译它们,public/assets/ 中似乎也有一个副本......
  • 你需要把你的css文件的扩展名从.css改成.css.scss
  • 我更改了扩展程序,但图像仍然没有出现。

标签: css ruby-on-rails heroku


【解决方案1】:

我遇到了同样的问题,我使用助手解决了。在你的 CSS 上试试这个:

background-image: image-url("hero-000.jpg");

【讨论】:

  • 不幸的是我试过了,但没有解决问题。
  • 尝试添加 gem: 'rails_12factor', group: :production
  • 这是为静态资源服务的
  • 我的制作组里确实有这颗宝石。
  • 您是否在终端上运行了 heroku run bash?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-07-10
  • 2020-10-20
  • 1970-01-01
  • 1970-01-01
  • 2012-02-08
相关资源
最近更新 更多