资产管道:排除 admin.css 文件

发布于 2025-01-05 02:48:21 字数 258 浏览 2 评论 0原文

我将 Rails 3.0 应用程序升级到 Rails 3.1,其中涉及将其放入

/*
*= require_self
*= require_tree .
*/

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

有没有办法排除 admin.css 文件被包含?在网站的管理部分,我手动包含 admin.css 文件,但我需要一种方法将其从用户界面中排除。

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

/*
*= require_self
*= require_tree .
*/

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

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

欲拥i 2025-01-12 02:48:21

您可以在清单中使用 stub sprockets' 指令,如下所示:

/*
*= require_self
*= require_tree .
*= stub admin
*/

这将排除 admin.css 以及其中所需的 ALL css!
因此,如果您的 admin.css 的清单看起来像这样:

/*
*= require bootstrap
*= require_self
*/

bootstrap.css 也将被排除,并且没有 require 可以解决这个问题!照顾好这个;)

You can use the stub sprockets' directive in your manifest like this :

/*
*= require_self
*= require_tree .
*= stub admin
*/

This will exclude admin.css and also ALL css required in it !!
So, if your admin.css's manifest seems like this :

/*
*= require bootstrap
*= require_self
*/

the bootstrap.css will also be excludes and no require could fixe this ! Take care of this ;)

羞稚 2025-01-12 02:48:21

之前曾提出过类似问题,您应该检查一下一个

Sprockets 使用清单文件来确定要包含和提供哪些资产。这些清单文件包含指令——告诉 Sprockets 构建单个 CSS 或 JavaScript 文件需要哪些文件的指令。使用这些指令,Sprockets 加载指定的文件,在必要时处理它们,将它们连接成一个文件,然后压缩它们(如果 Rails.application.config.assets.compress 为 true)。通过提供一个文件而不是多个文件,可以大大减少页面的加载时间,因为浏览器发出的请求更少。

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

特别是,您可以指定单个文件,它们会按照指定的顺序进行编译。

示例和更多详细信息可以在本指南中找到。

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

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

/* Other styles */

Similar question was asked earlier and you should check that one.

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.

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.

Thus, your new application.css would become:

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

/* Other styles */
小鸟爱天空丶 2025-01-12 02:48:21

另一种解决方案是在 app/assets/stylesheets 中有两个目录,例如 public 目录和 admin 目录。

然后,在 app/assets/stylesheets/application.css 中,您可以将 require_tree . 更改为 require_tree ./public

您可能需要在管理方面执行类似的操作。我碰巧正在使用 管理 gem,它知道在哪里可以找到自己的资产。

Another solution is to have two directories in app/assets/stylesheets, for example, a public directory and an admin directory.

Then, in app/assets/stylesheets/application.css, you can change require_tree . to require_tree ./public.

You might have to do something similar on the admin side. I happen to be using the Administrate gem which knows where to find its own assets.

也只是曾经 2025-01-12 02:48:21

解决方案是在 config/assets.rb 中添加

#config/assets.rb
Rails.application.config.assets.precompile  += %w(*.svg *.eot *.woff *.ttf *.gif *.png *.ico *.swf *.xap masonry.pkgd.min.js jquery.colorbox-min.js i18n/jquery.colorbox-pt-BR.js admin.css)

并在 app/views/layouts/_adm_layout.html.erb 中添加

#app/views/layouts/_adm_layout.html.erb
<%= stylesheet_link_tag 'admin', media: 'all', 'data-turbolinks-track' => true %>

soluction is add in config/assets.rb

#config/assets.rb
Rails.application.config.assets.precompile  += %w(*.svg *.eot *.woff *.ttf *.gif *.png *.ico *.swf *.xap masonry.pkgd.min.js jquery.colorbox-min.js i18n/jquery.colorbox-pt-BR.js admin.css)

And Add in app/views/layouts/_adm_layout.html.erb

#app/views/layouts/_adm_layout.html.erb
<%= stylesheet_link_tag 'admin', media: 'all', 'data-turbolinks-track' => true %>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文