0

I have an image: app/assets/images/oops.jpg

In 404.html I have:

<html>

<head>

  <title>Oops! Where are we?</title>
  <meta name="viewport" content="width=device-width,initial-scale=1">
  <style>
  body {
  background: url('oops.jpg') no-repeat center center fixed;
    -webkit-background-size: cover;
    -moz-background-size: cover;
    -o-background-size: cover;
    background-size: cover;
  }
  </style>
</head>

<body>


</body>
</html>

I confirmed that the image is indeed in production on Heroku, but the browser can not find the image.

Here is an image of my files.

enter image description here

What am I missing here?

Nitisha
  • 101
  • 12
gwalshington
  • 1,418
  • 2
  • 30
  • 60

5 Answers5

1

Try image path as "/assets/oops.jpg" or "../images/oops.jpg" this one too in another case . Assuming that you are using ruby on rails app from your path that you have mentioned. hope this will work for you.

Jai Chauhan
  • 4,035
  • 3
  • 36
  • 62
jacksonR
  • 25
  • 4
1

If your image is app/assets/images/oops.jpg

then your path to the image needs to be:

body {
  background: url('/app/assets/images/oops.jpg') no-repeat center center fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
  }
Wim Mertens
  • 1,780
  • 3
  • 20
  • 31
  • This returns a 440 not found – gwalshington Oct 04 '16 at 21:13
  • 1
    can you test in the browser with the full url to see if the image is loading: http://www.example.com/app/assets/images/oops.jpg – Wim Mertens Oct 04 '16 at 21:14
  • Or place the image in the root, and change the path to the image to url(/oops.jpg) – Wim Mertens Oct 04 '16 at 21:15
  • Interesting, it does not appear when I go to the equivalent of example.com/app/assets/images/oops.jpg. But I clearly see it in my repo. Thoughts on why this is? – gwalshington Oct 04 '16 at 21:17
  • 1
    did you upload your image to the server? Also, you might want to give the body a width and a height of 100% as well because it doesn't have any content – Wim Mertens Oct 04 '16 at 21:18
  • Yes, rails automatically complies assets, and I see it compiling the image when I push. I will try adding a width and height and see if it helps, but there is an error in my browser's console saying 404 not found for the image – gwalshington Oct 04 '16 at 21:20
  • If the image returns a 404 when you check in the browser, then there might be an issue with the compiling rather than the css path. Try uploading the image manually to the server. – Wim Mertens Oct 04 '16 at 21:23
  • And you're sure the name of the image (and extension) is correct? – Wim Mertens Oct 04 '16 at 21:27
  • I added a screenshot – gwalshington Oct 04 '16 at 21:32
  • Is app a folder on the server as well, or is assets in the root? If so then try this path: /assets/images/oops.jpg Make sure to test in the browser first to see if the image shows up – Wim Mertens Oct 04 '16 at 21:34
  • 1
    Here's a post that's related, maybe this is the issue: http://stackoverflow.com/questions/15354539/heroku-does-not-compile-files-under-assets-pipelines-in-rails-4 – Wim Mertens Oct 04 '16 at 21:37
  • Thanks! I saw that post previous to posting this. I have those gems set up. Also, I have several other images throughout the app, which work fine. I'm wondering if this is different since the rails 404.html page is in /public, instead of in views? – gwalshington Oct 04 '16 at 21:48
  • I'm not too familiar with Ruby, maybe best to add Ruby tags to your question rather than css. My best bet however would be to place the image in the root and change the css path to the image to url(/oops.jpg) – Wim Mertens Oct 04 '16 at 21:52
  • okay, I'll keep working on that, and add ruby to the question. Thank you so much for your help! – gwalshington Oct 04 '16 at 21:55
1
background: url('../images/oops.jpg') no-repeat center center fixed;
the Tin Man
  • 158,662
  • 42
  • 215
  • 303
Learn AspNet
  • 1,192
  • 3
  • 34
  • 74
1

I was also facing this issue while deploying a rails app on heroku in my case a little css change solved the problem

  body {
  background: asset-url('oops.jpg') no-repeat center center fixed;
    -webkit-background-size: cover;
    -moz-background-size: cover;
    -o-background-size: cover;
    background-size: cover;
  } 

use this asset-url instead of url property. hopefully it will solve your problem

Haider Bajwa
  • 114
  • 7
0

instead ... use this

body {
background: url('../images/oops.jpg');  

background-repeat: no-repeat;

background-size: 100% 100% ;
}
Zuma
  • 13
  • 5
  • 1
    Welcome to Stack Overflow! Thank you for this code snippet, which may provide some immediate help. A proper explanation [would greatly improve](//meta.stackexchange.com/q/114762) its educational value by showing *why* this is a good solution to the problem, and would make it more useful to future readers with similar, but not identical, questions. Please [edit] your answer to add explanation, and give an indication of what limitations and assumptions apply. – Toby Speight Aug 31 '17 at 12:23