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

后端 未结 6 824
北荒
北荒 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:34

    The following should do the trick:

    .button.checkable { background-image: url(image_path('tick.png')); }
    

    Rails in fact provides a bunch of helpers to reference the assets:

    image-url('asset_name')
    audio-path('asset_name')
    

    In general

    [asset_type]-url('asset_name') #Becomes url('assets/asset_name')
    [asset_type]-path('asset_name') #Becomes 'assets/asset_name'
    

    asset_type may be one of the following: image, font, video, audio, javascript, stylesheet

提交回复
热议问题