在Production中找不到文件’twitter / bootstrap’

我正在使用Twitter的Bootstrap翻译成SCSS文件。 它适用于本地开发,但是当我预编译并推送到Heroku(使用Cedar堆栈)时,我得到了这个:

> Started GET "/" for 74.57.16.130 at 2012-01-28 17:16:36 +0000 > Processing by StaticPagesController#home as HTML Rendered > static_pages/home.html.erb within layouts/application (0.7ms) > Completed 500 Internal Server Error in 4ms > > ActionView::Template::Error (couldn't find file 'twitter/bootstrap' > (in /app/app/assets/stylesheets/application.scss.css:11)): > 8:  > 6:  > 4:  > 2:  > 5:  "all" %> app/views/layouts/application.html.erb:5:in > `_app_views_layouts_application_html_erb___288948710373692320_32137840' > 3:  cache: [GET /] miss > > 7:  cache: [GET /favicon.ico] miss 

我正在使用Rails 3.2.0,该应用程序正在使用Heroku,直到我添加了SASS文件。

你在用gem吗? 确保您的gem不属于资产组,并且可以在生产中访问。

来自GemFile

 # Gems used only for assets and not in production environments by default. 

所以只需将gem移到任何一组之外,你应该没问题。

把它放在你的gemfile中

 gem "twitter-bootstrap-rails", "~> 2.0rc0" 

BootStrap 2.0中的CSS无效导致SCSS编译失败

您可以通过查看输出来validation这一点

 git push heroku master 

你应该看到一些错误:

 -----> Preparing app for Rails asset pipeline Running: rake assets:precompile rake aborted! Invalid CSS after "...er-radius:0 \0/": expected expression (eg 1px, bold), was ";}" (in /tmp/build_1k8ugei34dpcw/app/assets/stylesheets/application.css) Tasks: TOP => assets:precompile:primary (See full trace by running task with --trace) Precompiling assets failed, enabling runtime asset compilation Injecting rails31_enable_runtime_asset_compilation Please see this article for troubleshooting help: http://devcenter.heroku.com/articles/rails31_heroku_cedar#troubleshooting 

config/environments/production.rb添加以下行:

config.assets.precompile = [/^[-_a-zA-Z0-9]*\..*/]

我的猜测是它没有添加你所有的资产。

这至少解决了heroku中的问题

只是降级到sass-rails 3.1.4

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

当您将rails应用程序部署到heroku.com时,您会看到类似的内容

 Precompiling assets failed, enabling runtime asset compilation ... could not connect to server: Connection refused Is the server running on host "127.0.0.1" and accepting TCP/IP connections on port xxxx? 

只需将其添加到config / application.rb即可

 config.assets.initialize_on_precompile = false 

确保在config / environments / production.rb中,你有……

 config.serve_static_assets = true