为什么rails试图预编译.css文件

时间:2011-12-03 05:49:35

标签: ruby-on-rails ruby asset-pipeline

我正在使用Rails 3.1,在我的资产/样式表中,我有很多.css和.scss文件。

似乎Rails正在尝试预编译.css文件,然后他们会发布以下消息:

Invalid CSS after "...{padding-bottom": expected "{", was ";0;}#order_deta..."

如果我只有.css文件,如果我从Gemfile中注释掉sass-rails gem,那么一切正常。

group :assets do
  #gem 'sass-rails',   '~> 3.1.4'
  gem 'coffee-rails', '~> 3.1.1'
  gem 'uglifier', '>= 1.0.3'
end

所以现在的问题是,我是否必须将所有.css转换为.scss以便与资产预编译一起使用,或者是否有解决方法?

更新

这是我的代码:

config.assets.paths << "#{Rails.root}/app/themes/vanilla/assets/stylesheets"
config.assets.paths << "#{Rails.root}/app/themes/vanilla/assets/javascripts"
config.assets.paths << "#{Rails.root}/app/themes/vanilla/assets/images"
config.assets.precompile += ['vanilla.css', 'vanilla.js']

vanilla.css看起来像这样:

/*
 * This is a manifest file that'll automatically include all the stylesheets available in this directory
 * and any sub-directories. You're free to add application-wide styles to this file and they'll appear at
 * the top of the compiled file, but it's generally better to create a new file per style scope.
 *
 *= require 'reset'
 *= require 'vroom'
 *= require_self
*/

此处reset是reset.css,vroom是vroom.css.scss

这是我得到的错误:

Invalid CSS after "...{padding-bottom": expected "{", was ";0;}#order_deta..."
(in .........../stylesheets/vanilla.css)

发生此错误是因为Rails正在尝试预编译reset.css。

如果我删除了sass-rails gem和所有.scss文件,那么就可以使用资源:预编译工作。

2 个答案:

答案 0 :(得分:4)

您无需转换文件。这里发生的事情是SCSS处理器正在检查CSS文件的语法,即使它们没有作为SCSS处理。

密切关注被投诉的界限。错误似乎是说你在属性和值之间有分号(;)而不是冒号(:)

可能是这样的:

{padding-bottom;0;}

而不是:

{padding-bottom:0;}

通过删除gem,您将删除语法检查,因此文件将按原样编译。

答案 1 :(得分:1)

我遇到了同样的问题并找到了解决方案!

就我而言,我有这条线:

@import "bootstrap"

我所要做的只是添加分号

@import "bootstrap";

小而致命的错误!