【发布时间】: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