2

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!

2 Answers 2

4

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)}.
Sign up to request clarification or add additional context in comments.

Comments

3

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.

3 Comments

The README for sass-rails has more info on these new helpers. github.com/rails/sass-rails
Thanks, that's great. It solves the half of my problems. Still not sure what to do with vendor styles and js files.
This did work for me, but only if I used relative paths, not absolute ones. (And remembering to leave out the /assets in either case.) For vendored images (such as bootstrap glyphicons), I use public/img

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.