1

I manually added assets/images directory in a rails 3.2 app and added the image background.png . When referring to the image from css

background: url("assets/background.png") no-repeat;

I am getting a 404 , however assets/stylesheets and assets/javascripts are showing up.

**UPDATE

it appears as if I revert back to explicitly calling the stylesheet ie

<%=stylesheet_link_tag "home.css"%> 

instead of

<%=stylesheet_link_tag "application" %>

The background image reders correctly

marknery
  • 1,533
  • 3
  • 19
  • 27

2 Answers2

3

That url is relative to where the style sheet is. You probably want either url(../assets/background.png) to go up a level from your style sheet or url(/assets/background.png) to go from the root.

idrumgood
  • 4,904
  • 19
  • 29
  • 1
    I changed `background: url("assets/background.png") no-repeat;` to `background: url(image_url("background.png")) no-repeat;` which renders /assets/background.png . Also `url(../assets/background.png)` renders /assets/background.png also , however it still returning a 404 – marknery Apr 10 '12 at 17:10
0

Use:

url(<%= asset_path 'background.png' %>)

and you'll be fine.

jdoe
  • 15,665
  • 2
  • 46
  • 48
  • still is throwing me in the same directory as above solution – marknery Apr 10 '12 at 17:54
  • 1. did you restart your app after adding a folder? 2. did you check the characters case? maybe you've got a *.PNG file, not the *.png. – jdoe Apr 10 '12 at 18:03