Adding a background image in Ruby on Rails 2 in CSS

Dan picture Dan · Jan 26, 2012 · Viewed 65.3k times · Source

I generated a scaffold in ruby and I want to insert a background image to every page on the site but Im not sure what the link to the image should be.

my image is in app/assets/images/"dep.jpg"

this is what i have but it isnt working:

background-image:url('../images/dep.jpg');
}

Any help? thanks

Answer

Dylan Markow picture Dylan Markow · Jan 26, 2012

In Rails 3.1, the path will actually be `/assets/dep.jpg':

background-image: url(/assets/dep.jpg);

If you convert your scaffold.css file to a Sass file (rename to scaffold.css.scss) then you can use the helper:

background-image: image-url("dep.jpg");