1

I'm using rails 3 in production and development.

How do I use the asset_host path in css, for example with background-images?

I've tried:

.blerg{ background-image:url({asset_host}/images/blerg.gif); }

But it just comes out as that in the rendered document, is there anything special you have to do when including the css to get this to work?

CafeHey
  • 5,699
  • 19
  • 82
  • 145

3 Answers3

6

If you are using Rails 3.1 Asset Pipline you can use the following in sass/scss

.blerg{ background-image: image-url(blerg.gif); }

The added advantage of this approach is that in production the css image will also contain the MD5 fingerprinting so you can setup a far future expires header on your background images and still have them expire if you make changes to them.

Melzz
  • 61
  • 1
  • 4
1

If you are serving css files from asset host all relative linked images in your css file are served from the same host.

Jarek Zmudzinski
  • 7,121
  • 1
  • 15
  • 7
0

If you just do /assets/blerg.gif it should work fine.

Diego
  • 9
  • 2