28

编辑:我是一名新的 ruby​​ on rails 学生。

在我的 Git Push Heroku Master 之后,我遇到了 Heroku 的问题。这是最新最好的,中止 rake assets:precompile。

-----> Preparing app for Rails asset pipeline
   Running: rake assets:precompile
   rake aborted!
   could not connect to server: Connection refused
   Is the server running on host "127.0.0.1" and accepting
   TCP/IP connections on port 5432?
   Tasks: TOP => environment
   (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

以下是我的 Gemfile 的内容:

gem 'rails', '3.2.8'
gem 'bootstrap-sass', '2.1'
gem 'pg'

group :development, :test do
  gem 'rspec-rails'
  gem 'guard-rspec'
  gem 'guard-spork'
  gem 'spork'
  gem 'annotate'
  gem 'database_cleaner'
end

# Gems used only for assets and not required
# in production environments by default.
group :assets do
  gem 'sass-rails',   '~> 3.2.3'
end

platforms :jruby do
  gem 'trinidad'
  gem 'jruby-openssl'
end

gem 'jquery-rails'

# Use unicorn as the web server
# gem 'unicorn'

# Deploy with Capistrano
# gem 'capistrano'

# To use debugger
# gem 'ruby-debug'

# Bundle the extra gems:
gem 'RedCloth', '~> 4.2.9', :require => 'redcloth'
gem 'ruby-openid', :require => 'openid'
gem 'rack-openid', :require => 'rack/openid'
gem 'aaronh-chronic', :require => 'chronic' # Fixes for 1.9.2
gem 'coderay'
gem 'lesstile'
gem 'formtastic'
gem 'will_paginate', '~> 3.0.2'
gem 'exception_notification', '~> 2.5.2'
gem 'open_id_authentication'

# Bundle gems for the local environment. Make sure to
# put test-only gems in this group so their generators
# and rake tasks are available in development mode:
group :test do
  gem 'database_cleaner'
  gem 'cucumber-rails',    :require => false
  gem 'cucumber-websteps', :require => false
  gem 'factory_girl'
  gem 'rspec'
  gem 'nokogiri', '~> 1.5.0'
  gem 'webrat'
end

可能是什么问题?

更新:我用 --trace 运行了 rake 命令,它警告我失败,因为生产数据库不存在。我创建了数据库,然后再次运行 --trace,这就是我目前被抛出的内容:

Command failed with status (1): [/usr/local/Cellar/ruby/1.9.3-p286/bin/ruby...]
4

4 回答 4

56

请参阅Heroku Cedar 上的 Rails 3.1+ Asset Pipeline文章。故障排除部分介绍了这种确切的情况。

简而言之,您的 Heroku 应用程序在构建(包括资产编译)和运行(您的应用程序可用的地方)之间有很强的分离。这与12-factor app 原则是一致的,但这意味着您的应用程序在构建阶段无法访问任何已配置的资源——包括数据库——这意味着 ActiveRecord 在资产预编译期间不可用。

您可以告诉 Rails 在资产编译期间不要引导您的应用程序config/application.rb

config.assets.initialize_on_precompile = false

故障排除部分还建议:

如果 rake assets:precompile 仍然无法正常工作,您可以通过在本地配置一个不存在的数据库config/database.yml并尝试运行来在本地进行调试rake assets:precompile。理想情况下,您应该能够在不连接到数据库的情况下运行此命令。

于 2012-12-04T23:20:36.203 回答
13

今晚我为同样的问题苦苦挣扎了好几个小时。添加后

config.assets.initialize_on_precompile = false

到application.rb,记得做一个

git commit

紧接着。我忘了这样做,Heroku 不知道我更改了 application.rb。他们的故障排除页面上没有这条额外的行。

于 2013-09-11T08:34:28.140 回答
4

对于 Rails 4

启用 Heroku Labs 功能来解决这个问题

heroku 实验室:启用用户环境编译

于 2014-02-21T15:25:40.573 回答
3

我在 Rails 4 中遇到了这个问题,其他建议都没有帮助。我终于弄明白了,这是由于 Rollify gem 试图连接到数据库。这已在 Rollify gem 中修复,但是,您可能需要获取最新的源代码才能获得修复。我只是将 Rollify 的 gem 导入更改为:

gem 'rolify', :git => 'git://github.com/EppO/rolify.git'

这似乎解决了问题,我不必做任何其他建议。

不要忘记捆绑安装并将更改提交到 git。

此外,如果这也不能解决您的问题,您可能需要开始仔细查看您正在使用的 gem,并确保它们都没有尝试连接到数据库。

于 2014-03-20T15:57:17.013 回答