简体   繁体   中英

background image heroku rails not working

I have the background image for a basic rails site I made working fine but when I pushed it up to heroku it gave me the following error

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

here is the code from my css file

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;
}

I have several other pics uploaded and working fine anyone know why this is not working on heroku, but is still working locally?

try using image-url('joy.jpg') instead of url

This answer may give more info for you: How to reference images in CSS within Rails 4

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

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

I have also got this error, I have solved it by:

Production.rb

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

background-image: url(assets/hero_bg_2.jpg)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM