【发布时间】:2015-04-13 14:21:44
【问题描述】:
我刚刚启动了一个新的 Rails 项目,并试图从一个开源的 Rails 项目中参考他们如何构建他们的应用程序。
我注意到他们有多种布局,例如管理员,应用程序,家庭..等。每个都可以通过stylesheet_link_tag 加载到不同的样式表中。
例如在focus_home.html.erb:
<!-- Load styles -->
<%= stylesheet_link_tag 'focus_home' %>
<%= stylesheet_link_tag 'app/components/modal' %>
在他们的app/assets/stylesheets 目录中,他们有focus_home.scss
我尝试遵循他们的架构,我有多个 css 文件,并以不同的布局调用不同的样式表。
我创建了我的home.scss 供home.html.slim 使用
当我启动我的 Rails 服务器并尝试加载 home 页面时,出现以下错误
Asset filtered out and will not be served: add
`Rails.application.config.assets.precompile += %w( home.css )` to
`config/initializers/assets.rb` and restart your server
基本上它要求我告诉 Rails 预编译 home.scss。但是,当我浏览开源项目的代码库时。好像没有这行代码。预编译似乎就像魔术一样发生。
所以我想知道我错过了什么?
==============
编辑:进一步解释案例
在他们的项目中,他们没有像普通的 rails 项目一样有一个 application.css 文件。
/* * This is a manifest file that'll be compiled into application.css, which will include all the files * listed below. *
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets, * or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path. * * You're free to add application-wide styles to this file and they'll appear at the bottom of the * compiled file so the styles you add here take precedence over styles defined in any styles * defined in the other CSS/SCSS files in this directory. It is generally better to create a new * file per style scope. * *= require_tree . *= require_self */
相反,在他们的application.scss 中,它就像
@charset "utf-8";
@import "vars/base";
@import "constants";
// Libraries
@import 'bootstrap';
@import 'app/mixins/*';
@import 'basscss';
@import '_deprecated/basspluss';
@import '_deprecated/utility';
@import '_deprecated/nocss_vars';
@import '_deprecated/nocss';
@import '_deprecated/nocss_mq';
@import "app/main";
@import "base/*";
@import "utilities/*";
@import "app/components/*";
@import "components/*";
@import "app/slop";
@import 'libs/owl.carousel';
@import 'libs/owl.transitions';
@import 'libs/owl.theme';
@import 'c3/c3'
所以我想知道他们实际上是如何进行预编译的?
【问题讨论】:
-
将你的文件导入
application.scss,它应该在app/assets文件夹中 -
在开源项目中,在
app/assets/stylesheets/application.scss下 -
啊,好吧,这不是你的项目,我不确定结构是什么,但你可以将文件添加到包含在
app/assets/stylesheets/application.scss文件中的文件夹中 -
我不太确定的是他们如何处理 CSS 预编译。似乎他们没有
application.css和requires self and tree -
他们不需要,
application.scss做主
标签: ruby-on-rails ruby asset-pipeline