2012-12-04 101 views
27

编辑:我是一个新的红宝石轨道的学生。错误推向heroku - 堕落我的耙子资产:预编译

继我的Git Push Heroku Master后,我遇到了Heroku的问题。这是最新最好的,摒弃耙子资产:预编译。

-----> 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...] 

回答

56

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

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

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

config.assets.initialize_on_precompile = false 

故障排除部分还建议:

如果耙资产:预编译仍然没有工作,你可以通过在本地config/database.yml中配置不存在的数据库并尝试运行rake assets:precompile来在本地进行调试。理想情况下,您应该能够在不连接数据库的情况下运行此命令。

+1

这是我所需要的,非常感谢你。 –

+1

关键点在下面提到,确保你承诺改变! – CJBrew

13

我挣扎着与同样的问题,今晚数小时。加入

config.assets.initialize_on_precompile = false 

到application.rb中后,记得要做一次

git commit 

权之后。我忘了这么做,Heroku不知道我已经改变了application.rb。他们的故障排除页面上没有这个额外的行。

4

对于轨道4

启用Heroku的实验室功能来解决这个问题

Heroku的实验室:启用用户ENV编译

+1

看起来这是退役的。 https://devcenter.heroku.com/changelog-items/416 –

+0

Thanks @ andy-atkinson –

3

我曾就此问题与轨道4,没有的其他建议帮助。我终于弄明白了,这是由于Rollify gem试图连接到数据库。这已经在Rollify gem中得到修复,但是,您可能需要获取最新的源代码才能获得修复。我只是改变我的宝石进口的Rollify到:

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

这似乎解决这个问题,我没有做任何的其他建议。

不要忘了捆绑安装,并承诺将改变饭桶。另外,如果这样也不能解决您的问题,您可能需要开始仔细查看您正在使用的宝石,并确保它们都不会尝试连接到数据库。