开发者

How to make assets in SASS?

In Rails, when we include an image开发者_运维问答 into the page we use image_tag helper, which generates <img> tag and adds ?nnnnn at the end of its url, so that every time an image is updated the old version would not be stuck in the cache on the client side. Same thing for SASS needed, but I can't find it in the documentation.


You should be using helpers provided by sass-rails gem https://github.com/rails/sass-rails, (scroll to Asset Helpers). These helpers can be used from inside sass files any time you need to reference an asset (image/audio/video/font)

body{ background: asset_path($relative-asset-path, $asset-class); }

Note: image_url("...") is not working on Rails 3.1.0.rc4 due to a bug, but you can still use asset_url and asset_path.


Using stylesheet_link_tag will do this for you, just the same as image_tag does. This also applies to JavaScript files linked in with javascript_include_tag.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜