【问题标题】:background image heroku rails not working背景图像 heroku rails 不工作
【发布时间】:2014-02-28 00:34:54
【问题描述】:

我有一个基本的 Rails 网站的背景图片,但当我把它推到 heroku 时,它给了我以下错误

Failed to load resource: the server responded with a status of 404 (Not Found) http://young-oasis-2855.herokuapp.com/assets/joy.jpg

这是我的 css 文件中的代码

body {
  background: url(/assets/joy.jpg) no-repeat center center fixed;
  -webkit-background-size: cover;
  -moz-background-size: cover;
  -o-background-size: cover;
  background-size: cover;
}

我上传了其他几张图片并且工作正常,有人知道为什么这在 heroku 上不起作用,但仍在本地工作吗?

【问题讨论】:

标签: css ruby-on-rails heroku


【解决方案1】:

尝试使用image-url('joy.jpg') 代替网址

此答案可能会为您提供更多信息: How to reference images in CSS within Rails 4

【讨论】:

  • 你知道为什么使用 image-url 可以在 heroku 上正常工作吗?
  • 因为在本地,您没有使用资产管道。如果您想更深入地了解,您需要研究资产管道的工作原理。注意:在您部署到的任何服务器上都会出现此问题 - 一旦进入生产模式。
【解决方案2】:

同样,我也使用过这样的 CSS 属性。

background-image:url('joy.jpg');

【讨论】:

    【解决方案3】:

    我也遇到了这个错误,我已经解决了:

    生产.rb

    config.cache_classes = true
    config.assets.compile = true
    

    背景图片:url(assets/hero_bg_2.jpg)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-09-20
      • 2015-12-10
      • 1970-01-01
      • 1970-01-01
      • 2016-10-10
      • 1970-01-01
      • 2016-09-23
      相关资源
      最近更新 更多