如何在 Rails 3.1 应用程序中处理 CSS 中的图像引用 [英] How to deal with image references in CSS in a Rails 3.1 app

查看:30
本文介绍了如何在 Rails 3.1 应用程序中处理 CSS 中的图像引用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚将 Rails 应用升级到 3.1,并且正在使用新的资产管道.管道就位后,您的应用程序中的任何静态引用都必须使用 rails 辅助方法,即 asset_path(...)、img_tag() 等....

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....

问题来了,如何修复我的 css 文件中的静态引用?

Here's the question, how do I fix the static references in my css files?

推荐答案

在 Rails 的 SASS 文件中,有一个 image-url() 函数,你可以像这样使用:

In Rails' SASS files, there's an image-url() function you can use like so:

.page {
    background: #eee image-url('somefile.png');
}

Rails 将在所有资产图像目录中查找该文件,例如 app/assets/images/somefile.png.

Rails will look for that file in all the asset images directories, such as app/assets/images/somefile.png.

查看 sass-rails 的自述文件,了解更多辅助方法以及 Asset Pipeline Rails 指南 以获得进一步的文档和解释.

Check the readme for sass-rails for more helper methods, as well as the Asset Pipeline Rails guide for further documentation and explanation.

这篇关于如何在 Rails 3.1 应用程序中处理 CSS 中的图像引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆