问题
I just upgraded my rails app to 3.1 and I'm making use of the new asset pipeline. With the pipeline in place it's imperative that any static references made in your application utilize the rails helper methods, ie, asset_path(...), img_tag(), etc....
Here's the question, how do I fix the static references in my css files?
回答1:
In Rails' SASS files, there's an image-url()
function you can use like so:
.page {
background: #eee image-url('somefile.png');
}
Rails will look for that file in all the asset images directories, such as app/assets/images/somefile.png
.
Check the readme for sass-rails for more helper methods, as well as the Asset Pipeline Rails guide for further documentation and explanation.
回答2:
If you work with in engine or plugin, this might not work. In any case you can always use the generic method:
asset-url("rails.png", image)
来源:https://stackoverflow.com/questions/7375568/how-to-deal-with-image-references-in-css-in-a-rails-3-1-app