welldan97
welldan97

Reputation: 3076

Rails 3.1: Access a fingerprinted image from css

Is there an elegant way to access images with fingerprints in production from css?

I know I can use erb for css, but adding urls with erb looks ugly, and I think it should be someway automated. Besides I don't want to change vendor stylesheets.

Thanks!

Upvotes: 2

Views: 1784

Answers (2)

A B
A B

Reputation: 2091

I think image-url should solve this problem

.btn_back:hover {background-image: image-url('btn_back_push.png');}

it works for me in dev. mode as well as in the production with precompiled assets as result

dev. mode:

.btn_nav:hover {
  background-image: url("btn_nav_push.png");
}

production:

.btn_nav:hover{background-image:url(/assets/btn_nav_push-094b577d7e9e1cc6d5aced334f3fe8b3.png)}.

Upvotes: 4

dpb
dpb

Reputation: 671

sass-rails has added a helper for this called image-path. You can use it like this:

#image { background: image-path("rails.png") }

This won't work for normal css files, but because scss is a superset of css, so you should be able to change the extension to .scss and all will be good.

Upvotes: 3

Related Questions