资产管道:排除admin.css文件 [英] Asset Pipeline: excluding an admin.css file

查看:82
本文介绍了资产管道:排除admin.css文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将一个Rails 3.0应用程序升级到了Rails 3.1,其中涉及到放置

I upgraded a Rails 3.0 app to Rails 3.1 which involved putting this

/*
*= require_self
*= require_tree .
*/

在application.css文件中.但是,有一个admin.css文件现在可以覆盖主应用程序css文件.

in the application.css file. However, there's an admin.css file that's now overriding the main app css file.

是否有一种方法可以将admin.css文件排除在外?在网站的管理"部分中,我手动添加了admin.css文件,但我需要一种从用户界面中将其排除的方法.

Is there a way to exclude the admin.css file from being included? In the admin section of the site I manually include the admin.css file but I need a way to exclude it from the user interface.

推荐答案

Sprockets使用清单文件来确定要包括和服务的资产.这些清单文件包含指令-指示Sprockets生成单个CSS或JavaScript文件需要哪些文件的指令.使用这些指令,Sprockets加载指定的文件,在必要时对其进行处理,将它们串联为一个文件,然后进行压缩(如果Rails.application.config.assets.compress为true).通过提供一个文件而不是多个文件,由于浏览器发出的请求更少,因此页面的加载时间可以大大减少.

Sprockets uses manifest files to determine which assets to include and serve. These manifest files contain directives — instructions that tell Sprockets which files to require in order to build a single CSS or JavaScript file. With these directives, Sprockets loads the files specified, processes them if necessary, concatenates them into one single file and then compresses them (if Rails.application.config.assets.compress is true). By serving one file rather than many, the load time of pages can be greatly reduced because the browser makes fewer requests.

您可以根据需要拥有任意数量的清单文件.例如,admin.css和admin.js清单可能包含用于应用程序admin部分的JS和CSS文件.

You can have as many manifest files as you need. For example the admin.css and admin.js manifest could contain the JS and CSS files that are used for the admin section of the application.

尤其是,您可以指定单个文件,并按照指定的顺序进行编译.

In particular, you can specify individual files and they are compiled in the order specified.

示例和更多详细信息可以在本指南.

Example and more details can be found in this guide.

因此,您的新application.css将变为:

Thus, your new application.css would become:

/*
 *= require styles
 *= require layout
 */

/* Other styles */

这篇关于资产管道:排除admin.css文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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