0

Background image style works fine on local as there is no digest on locale, but on production, after assets:precompile, all assets add fingerprints and there is no non-digested asset names in Rails 4. Due to this,

background-image: url('abc.png')

does not work.

Is there any way to let background images work after assets:precompile?

sawa
  • 165,429
  • 45
  • 277
  • 381
Haseeb Ahmad
  • 7,914
  • 12
  • 55
  • 133

3 Answers3

3

Try this. The file extension should be scss, will not work in css file.

background-image: url(asset_path('abc.png'));
Kalpesh Fulpagare
  • 1,309
  • 10
  • 18
2

In CSS use

background-image: url(<%= asset_path 'abc.png' %>)

https://guides.rubyonrails.org/asset_pipeline.html#css-and-erb

and in Sass

image-url("abc.png") 
image-path("abc.png")

https://guides.rubyonrails.org/asset_pipeline.html#css-and-sass

mrzasa
  • 22,895
  • 11
  • 56
  • 94
0

I'd make sure that your filename has not spaces. This was the issue in my case.

daxtersky
  • 410
  • 3
  • 9