1

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?

  • possible duplicate of [How to reference images in CSS within Rails 4](http://stackoverflow.com/questions/15257555/how-to-reference-images-in-css-within-rails-4) – Taryn East Feb 28 '14 at 00:44

3 Answers3

2

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

Community
  • 1
  • 1
Taryn East
  • 27,486
  • 9
  • 86
  • 108
  • do you know why using image-url makes this work on heroku, when it works fine locally? –  Feb 28 '14 at 01:15
  • Because locally, you aren't using the asset pipeline. You'll need to look into how the asset pipeline works if you'd like a deeper understanding. Note: this problem would occur on any server that you deploy to - once it goes into production mode. – Taryn East Feb 28 '14 at 01:56
0

Similarly, I've used a CSS property like this.

background-image:url('joy.jpg');
chrisfin
  • 21
  • 7
0

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)