3

i'm using the asset pipeline with rails 3.1 and less.

i have my images stored in app/assets/images.

in my .css.less file i have:

background-image: url('image.gif');

when the stylesheet gets compiled, it renders the path to the image as follows:

background-image: url('/images/image.gif')

when these images are requested through webrick, webrick is returning a 406 error code for those requests. manually requesting http://localhost/images/image.gif also returns a 406.

however, a request to http://localhost/assets/image.gif works just fine.

when i access the rails server through passenger, using the /images/image.gif path works, as does /assets/image.gif.

I also tried changing the file to be a .erb file and then using asset_path, with the same results.

I also tried to manually force the /assets path by using this in the .css.less file:

background-image: url('/assets/image.gif')

but that still compiles the css file to use /images/image.gif

kclair
  • 2,124
  • 1
  • 14
  • 18

1 Answers1

2

Try this instead:

background-image: asset-url('image.gif', image);

algi
  • 567
  • 5
  • 13
  • I'm not using sass, which I understand should support asset-url. It doesn't seem to work with Less. Some things online say that asset_url should work as ruby code, but that method isn't recognized in my environment. I notice that in my sprockets gem source, the function asset_url is defined but both empty and commented out. – kclair Nov 23 '11 at 21:19
  • seems like the less-rails gem is missing the asset helper to create the correct path to the images. https://github.com/metaskills/less-rails/issues/1 -- seems like these are added in unreleased version 2.0.2 – kclair Nov 23 '11 at 21:35