我想部署到Heroku但我有一个错误:
预编译资产失败。
注意:我已将config.assets.initialize_on_precompile = false
放入我的application.rb中,但它仍无效。
`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?
/tmp/build_9ff1fa36-2743-4f79-a9ac-62679367458b/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.0/lib/active_record/connection_adapters/postgresql_adapter.rb:825:in `initialize'
/tmp/build_9ff1fa36-2743-4f79-a9ac-62679367458b/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.0/lib/active_record/connection_adapters/postgresql_adapter.rb:825:in `new'
/tmp/build_9ff1fa36-2743-4f79-a9ac-62679367458b/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.0/lib/active_record/connection_adapters/postgresql_adapter.rb:825:in `connect'
/tmp/build_9ff1fa36-2743-4f79-a9ac-62679367458b/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.0/lib/active_record/connection_adapters/postgresql_adapter.rb:542:in `initialize'
/tmp/build_9ff1fa36-2743-4f79-a9ac-62679367458b/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.0/lib/active_record/connection_adapters/postgresql_adapter.rb:41:in `new'
/tmp/build_9ff1fa36-2743-4f79-a9ac-62679367458b/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.0/lib/active_record/connection_adapters/postgresql_adapter.rb:41:in `postgresql_connection'
/tmp/build_9ff1fa36-2743-4f79-a9ac-62679367458b/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:440:in `new_connection'
/tmp/build_9ff1fa36-2743-4f79-a9ac-62679367458b/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:450:in `checkout_new_connection'
/tmp/build_9ff1fa36-2743-4f79-a9ac-62679367458b/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:421:in `acquire_connection'
/tmp/build_9ff1fa36-2743-4f79-a9ac-62679367458b/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:356:in `block in checkout'
/tmp/build_9ff1fa36-2743-4f79-a9ac-62679367458b/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:355:in `checkout'
/tmp/build_9ff1fa36-2743-4f79-a9ac-62679367458b/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:265:in `block in connection'
/tmp/build_9ff1fa36-2743-4f79-a9ac-62679367458b/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:264:in `connection'
/tmp/build_9ff1fa36-2743-4f79-a9ac-62679367458b/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:546:in `retrieve_connection'
/tmp/build_9ff1fa36-2743-4f79-a9ac-62679367458b/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.0/lib/active_record/connection_handling.rb:79:in `retrieve_connection'
/tmp/build_9ff1fa36-2743-4f79-a9ac-62679367458b/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.0/lib/active_record/connection_handling.rb:53:in `connection'
/tmp/build_9ff1fa36-2743-4f79-a9ac-62679367458b/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.0/lib/active_record/model_schema.rb:203:in `table_exists?'
/tmp/build_9ff1fa36-2743-4f79-a9ac-62679367458b/vendor/bundle/ruby/2.0.0/gems/rolify-3.4.0/lib/rolify/configure.rb:48:in `block in sanity_check'
/tmp/build_9ff1fa36-2743-4f79-a9ac-62679367458b/vendor/bundle/ruby/2.0.0/gems/rolify-3.4.0/lib/rolify/configure.rb:46:in `each'
/tmp/build_9ff1fa36-2743-4f79-a9ac-62679367458b/vendor/bundle/ruby/2.0.0/gems/rolify-3.4.0/lib/rolify/configure.rb:46:in `sanity_check'
/tmp/build_9ff1fa36-2743-4f79-a9ac-62679367458b/vendor/bundle/ruby/2.0.0/gems/rolify-3.4.0/lib/rolify/configure.rb:7:in `configure'
/tmp/build_9ff1fa36-2743-4f79-a9ac-62679367458b/config/initializers/rolify.rb:1:in `<top (required)>'
/tmp/build_9ff1fa36-2743-4f79-a9ac-62679367458b/vendor/bundle/ruby/2.0.0/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:222:in `load'
/tmp/build_9ff1fa36-2743-4f79-a9ac-62679367458b/vendor/bundle/ruby/2.0.0/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:222:in `block in load'
/tmp/build_9ff1fa36-2743-4f79-a9ac-62679367458b/vendor/bundle/ruby/2.0.0/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:213:in `load_dependency'
/tmp/build_9ff1fa36-2743-4f79-a9ac-62679367458b/vendor/bundle/ruby/2.0.0/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:222:in `load'
/tmp/build_9ff1fa36-2743-4f79-a9ac-62679367458b/vendor/bundle/ruby/2.0.0/gems/railties-4.0.0/lib/rails/engine.rb:609:in `block (2 levels) in <class:Engine>'
/tmp/build_9ff1fa36-2743-4f79-a9ac-62679367458b/vendor/bundle/ruby/2.0.0/gems/railties-4.0.0/lib/rails/engine.rb:608:in `each'
/tmp/build_9ff1fa36-2743-4f79-a9ac-62679367458b/vendor/bundle/ruby/2.0.0/gems/railties-4.0.0/lib/rails/engine.rb:608:in `block in <class:Engine>'
/tmp/build_9ff1fa36-2743-4f79-a9ac-62679367458b/vendor/bundle/ruby/2.0.0/gems/railties-4.0.0/lib/rails/initializable.rb:30:in `instance_exec'
/tmp/build_9ff1fa36-2743-4f79-a9ac-62679367458b/vendor/bundle/ruby/2.0.0/gems/railties-4.0.0/lib/rails/initializable.rb:30:in `run'
/tmp/build_9ff1fa36-2743-4f79-a9ac-62679367458b/vendor/bundle/ruby/2.0.0/gems/railties-4.0.0/lib/rails/initializable.rb:55:in `block in run_initializers'
/tmp/build_9ff1fa36-2743-4f79-a9ac-62679367458b/vendor/bundle/ruby/2.0.0/gems/railties-4.0.0/lib/rails/initializable.rb:44:in `each'
/tmp/build_9ff1fa36-2743-4f79-a9ac-62679367458b/vendor/bundle/ruby/2.0.0/gems/railties-4.0.0/lib/rails/initializable.rb:44:in `tsort_each_child'
/tmp/build_9ff1fa36-2743-4f79-a9ac-62679367458b/vendor/bundle/ruby/2.0.0/gems/railties-4.0.0/lib/rails/initializable.rb:54:in `run_initializers'
/tmp/build_9ff1fa36-2743-4f79-a9ac-62679367458b/vendor/bundle/ruby/2.0.0/gems/railties-4.0.0/lib/rails/application.rb:215:in `initialize!'
/tmp/build_9ff1fa36-2743-4f79-a9ac-62679367458b/vendor/bundle/ruby/2.0.0/gems/railties-4.0.0/lib/rails/railtie/configurable.rb:30:in `method_missing'
/tmp/build_9ff1fa36-2743-4f79-a9ac-62679367458b/config/environment.rb:5:in `<top (required)>'
/tmp/build_9ff1fa36-2743-4f79-a9ac-62679367458b/vendor/bundle/ruby/2.0.0/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:228:in `require'
/tmp/build_9ff1fa36-2743-4f79-a9ac-62679367458b/vendor/bundle/ruby/2.0.0/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:228:in `block in require'
/tmp/build_9ff1fa36-2743-4f79-a9ac-62679367458b/vendor/bundle/ruby/2.0.0/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:213:in `load_dependency'
/tmp/build_9ff1fa36-2743-4f79-a9ac-62679367458b/vendor/bundle/ruby/2.0.0/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:228:in `require'
/tmp/build_9ff1fa36-2743-4f79-a9ac-62679367458b/vendor/bundle/ruby/2.0.0/gems/railties-4.0.0/lib/rails/application.rb:189:in `require_environment!'
/tmp/build_9ff1fa36-2743-4f79-a9ac-62679367458b/vendor/bundle/ruby/2.0.0/gems/railties-4.0.0/lib/rails/application.rb:249:in `block in run_tasks_blocks'
/tmp/build_9ff1fa36-2743-4f79-a9ac-62679367458b/vendor/bundle/ruby/2.0.0/gems/sprockets-rails-2.0.1/lib/sprockets/rails/task.rb:54:in `block (2 levels) in define'
Tasks: TOP => environment
(See full trace by running task with --trace)
! !预编译资产失败。 !尝试访问不存在的数据库: ! https://devcenter.heroku.com/articles/pre-provision-database !
!推送拒绝,无法编译Ruby app`
谢谢!
答案 0 :(得分:2)
设置此代码后:config.assets.initialize_on_precompile = false
heroku
之前不要忘记提交更改:
git commit -m
git push
到您的github远程仓库
然后git push heroku master
只要您对文件进行了更改,就需要先将commit
然后push
添加到远程仓库,然后再推送到heroku
。否则,heroku不会选择更改。
更新:
Heroku解决了同样的问题here。按照他们的解决方案
答案 1 :(得分:1)
感谢最后的答案,我有同样的问题,这对我有用。我只想添加从一般宝石中删除sqlite3并将其放入开发组中:
group :development, :test do
gem 'sqlite3'
end
group :production do
gem 'pg', '0.17.1'
gem 'rails_12factor','0.0.2'
end
当然,这就是诀窍
heroku addons:add heroku-postgresql
答案 2 :(得分:0)
试试这个:
1)首先打开您的Gemfile并删除gem 'sqlite3'
,像这样替换:
group :production do
gem 'pg', '0.17.1'
gem 'rails_12factor','0.0.2'
end
2)然后运行bundle install
3)打开你的config / application.rb并修改如下:
production:
adapter: postgresql
encoding: unicode
database: db/production.postgresql
pool: 5
username: test_postgre
password:
记住git commit并推送它。
4)然后运行heroku addons:add heroku-postgresql
5)现在你可以运行git push heroku master