我拼命地试图将我的应用程序推送到heroku但它失败并显示此错误消息。 它适用于我的本地机器,但我甚至无法将其推送到heroku。 我一直试图让这项工作好几天,但是找不到。
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?
Running: rake assets:precompile
Running: rake assets:precompile
Connecting to database specified by DATABASE_URL
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?
/tmp/build_6c1232cd-5bee-4760-a11c-1745627fba6e/vendor/bundle/ruby/2.0.0/gems/activerecord-3.2.14/lib/active_record/connection_adapters/postgresql_adapter.rb:1222:in `initialize'
/tmp/build_6c1232cd-5bee-4760-a11c-1745627fba6e/vendor/bundle/ruby/2.0.0/gems/activerecord-3.2.14/lib/active_record/connection_adapters/postgresql_adapter.rb:1222:in `new'
/tmp/build_6c1232cd-5bee-4760-a11c-1745627fba6e/vendor/bundle/ruby/2.0.0/gems/activerecord-3.2.14/lib/active_record/connection_adapters/postgresql_adapter.rb:1222:in `connect'
....
/tmp/build_6c1232cd-5bee-4760-a11c-1745627fba6e/vendor/bundle/ruby/2.0.0/gems/actionpack-3.2.14/lib/sprockets/assets.rake:93:in `block (2 levels) in <top (required)>'
/tmp/build_6c1232cd-5bee-4760-a11c-1745627fba6e/vendor/bundle/ruby/2.0.0/gems/actionpack-3.2.14/lib/sprockets/assets.rake:60:in `block (3 levels) in <top (required)>'
/tmp/build_6c1232cd-5bee-4760-a11c-1745627fba6e/vendor/bundle/ruby/2.0.0/gems/actionpack-3.2.14/lib/sprockets/assets.rake:23:in `invoke_or_reboot_rake_task'
/tmp/build_6c1232cd-5bee-4760-a11c-1745627fba6e/vendor/bundle/ruby/2.0.0/gems/actionpack-3.2.14/lib/sprockets/assets.rake:29:in `block (2 levels) in <top (required)>'
Tasks: TOP => environment
(See full trace by running task with --trace)
!
! Precompiling assets failed.
!
! Push rejected, failed to compile Ruby app
这是我的宝石文件
来源'http://rubygems.org' ruby'2.0.0'
gem 'rails', '3.2.14'
gem 'json'
gem 'thin'
gem 'rails_12factor'
gem 'paymill'
gem 'pg', "0.16.0"
gem 'haml'
gem 'jammit', :git => 'https://github.com/documentcloud/jammit.git', :branch => 'master'
gem 'sass-rails'
gem 'uglifier'
gem 'aws-s3'
gem 'aws-sdk'
gem 'friendly_id'
gem 'devise', '~> 2.2.7'
gem 'activeadmin', "0.6.0"
gem 'formtastic'
gem 'inherited_resources'
gem 'paperclip', '~> 2.4'
gem 'country_select'
gem 'coffee-script'
group :development, :test do
gem 'escape_utils'
gem 'rails-footnotes'
gem 'rack-webconsole'
gem 'better_errors'
gem 'binding_of_caller'
gem 'pry'
gem 'pry-debugger'
end
group :test do
gem 'factory_girl_rails', '~> 4.1.0'
gem 'rspec-rails', '~> 2.14.0'
gem 'cucumber-rails', '~> 1.4.0', require: false
gem 'database_cleaner', '~> 1.0.1'
# gem 'capybara', '~> 2.1.0'
gem 'simplecov', require: false
end
答案 0 :(得分:2)
好的,我刚刚在我的应用中解决了这个问题。
诀窍在于故障排除文档https://devcenter.heroku.com/articles/rails-asset-pipeline#troubleshooting:
资产失败的最常见原因:预编译是一个依赖于启动其环境的应用程序。在slug编译期间,你的应用程序的配置变量在环境中不存在,所以你应该采取措施来处理初始化程序中配置变量(和附加资源)的nil情况。
在Rails 3.x中,您可以通过确保config / application.rb中包含以下行来阻止初始化应用程序并连接到数据库:
config.assets.initialize_on_precompile = false
更改此设置后不要忘记提交git。
在这一步中,有更多关于这个答案的解释:Error pushing to heroku - aborting my rake assets:precompile
答案 1 :(得分:0)
你可以修改你的gemfile吗?
group :development, :test do
gem 'sqlite3'
end
group :production do
gem 'pg'
gem 'rails_12factor'
end
所以基本上添加这三颗宝石。 然后执行“捆绑安装”,然后将其推送到Heroku。 希望这有效。
答案 2 :(得分:0)
尝试以下
$ heroku labs:enable user-env-compile
其中一个gem可能导致的问题是在资产预编译期间尝试连接到数据库。检查Heroku Labs: user-env-compile的heroku文档,看看它是如何工作的。