我创建了一个全新的Rails 3.1应用程序.我在app / assets / stylesheets / bootstrap.min.css中添加了twitter bootstrap CSS文件.这是相关的代码
app / assets / stylesheets / application.css(包括树,所以包含bootstrap)
/* * 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_self *= require_tree . */
Gemfile(包括用于编译/压缩的execjs和therubyracer)
group :development,:qa do gem 'execjs' gem 'therubyracer' end # Gems used only for assets and not required # in production environments by default. group :assets do gem 'sass-rails','~> 3.1.0' gem 'coffee-rails','~> 3.1.0' gem 'uglifier','>= 1.0.3' end
然后我运行rake任务来预编译资产
rake assets:precompile
这失败,出现以下错误
Invalid CSS after ".inputs-list li+": expected number or function,was "li"
CSS在引导程序文件中(“.inputs-list li li”是选择器).
但是,如果我跑
rake assets:precompile RAILS_ENV=development
现在它工作正常.事实证明,如果我将config / environments / production.rb更改为不压缩文件:
config.assets.compress = false
那么原始命令也可以工作(没有指定开发环境).
那么,我该如何追踪错误?我现在可以忍受只是关闭压缩,但显然有些不对劲.是Rails吗?链轮?ruby赛车? Uglifier?
解决方法
我使用非缩小版的Bootstrap修复了这个问题.在运行rake资产时它仍然会被编译:预编译所以它不是问题:)