Rails 3.1 and Image Assets

后端 未结 7 1958
深忆病人
深忆病人 2020-11-30 16:53

I have put all my images for my admin theme in the assets folder within a folder called admin. Then I link to it like normal ie.

# Ruby    
image_tag \"admin         


        
7条回答
  •  忘掉有多难
    2020-11-30 17:10

    The asset pipeline in rails offers a method for this exact thing.

    You simply add image_path('image filename') to your css or scss file and rails takes care of everything. For example:

    .logo{ background:url(image_path('admin/logo.png'));

    (note that it works just like in a .erb view, and you don't use "/assets" or "/assets/images" in the path)

    Rails also offers other helper methods, and there's another answer here: How do I use reference images in Sass when using Rails 3.1?

提交回复
热议问题