未在Heroku中显示CSS背景图像

未在Heroku中显示CSS背景图像,css,ruby-on-rails,heroku,Css,Ruby On Rails,Heroku,我已经在SO和其他帮助网站上阅读了大量关于这个问题的帖子,但到目前为止没有任何帮助。我的CSS中有一些图像显示在我的localhost上,但当我将我的应用程序推到Heroku时,这些图像不会显示 下面是一个图像示例: .hero-000 { width: 102%; background: url(hero-000.jpg) no-repeat center center fixed; -webkit-background-size: cover; -moz-ba

我已经在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;
}
根据其他帖子的建议,我已将此添加到我的
应用程序中。rb

config.assets.initialize_on_precompile = false
  config.serve_static_files = true
  config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect'
  config.assets.compile = true
  config.assets.digest = true
我还将此添加到了我的
production.rb

config.assets.initialize_on_precompile = false
  config.serve_static_files = true
  config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect'
  config.assets.compile = true
  config.assets.digest = true
我按照Heroku网站上的步骤预编译资产


我真的不知道该怎么办,所以非常感谢您的帮助。

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

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

在css:background image:image url(“hero-000.jpg”)中这样指定图像路径,您的
hero-000.jpg
文件在哪里?@pardepsaini这样做会使图像在我的
localhost
上消失。和@uzai如果图像在
app/assets/images/
中,但由于我尝试预编译它们,因此在
public/assets/
中似乎也有一个副本…您需要将css文件的扩展名从
.css
更改为
。css.scss
我更改了扩展名,但图像仍然没有显示。不幸的是,我尝试了但这并没有解决问题。尝试添加gem:'rails_12factor',group::production这是为了服务静态资产我的生产组中确实有这个gem。你在终端上运行了heroku run bash吗?