How do I use reference images in Sass when using Rails 3.1?

后端 未结 6 810
北荒
北荒 2020-12-12 19:29

I have a Rails 3.1 project with the asset pipeline working great. The problem is that I need to reference images in my Sass, but Rails calculates image URLs. (This is partic

6条回答
  •  眼角桃花
    2020-12-12 19:47

    When using the asset pipeline, paths to assets must be re-written and sass-rails provides -url and -path helpers (hyphenated in Sass, underscored in Ruby) for the following asset classes: image, font, video, audio, JavaScript and stylesheet.

    image-url("rails.png") returns url(/assets/rails.png) image-path("rails.png") returns "/assets/rails.png"

    The more generic form can also be used:

    asset-url("rails.png") returns url(/assets/rails.png) asset-path("rails.png") returns "/assets/rails.png"

提交回复
热议问题