我使用的是 Rails 3.1,在我的 Assets /样式表中有一堆 .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 才能很好地进行 Assets 预编译,或者是否有解决方法?
更新:
这是我的代码:
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 文件,那么 rake assets:precompile 工作。
最佳答案
您不必转换文件。这里发生的是 SCSS 处理器正在检查你的 CSS 文件的语法,即使它们没有作为 SCSS 处理。
仔细查看被投诉的线路。该错误似乎是说您在属性和值之间有分号 (;) 而不是冒号 (:)
可能是这样的:
{padding-bottom;0;}
而不是这个:
{padding-bottom:0;}
通过删除 gem,您将删除语法检查,因此文件将按原样编译。
关于ruby-on-rails - 为什么 Rails 试图预编译 .css 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8365846/