Rails 4 - 生产资产:预编译导致 ActiveRecord::NoDatabaseError: FATAL: database does not exist
Posted
技术标签:
【中文标题】Rails 4 - 生产资产:预编译导致 ActiveRecord::NoDatabaseError: FATAL: database does not exist【英文标题】:Rails 4 - Production assets:precompile results in ActiveRecord::NoDatabaseError: FATAL: database does not exist 【发布时间】:2015-01-20 08:19:06 【问题描述】:似乎无法弄清楚为什么在推送到 Heroku 之前我不能再预编译资产。详情如下。当前运行 Rails 4.1.6。其他一些可能相关的信息:
捆绑器版本 1.7.12。 gem 'activeadmin',github:'activeadmin' 宝石'formtastic','3.1.2'
当 config.assets.initialize_on_precompile = false 可以修复它时,我只能找到对 pre-Rails 4 的引用,这不再适用。
任何想法为什么它试图连接到数据库?
> RAILS_ENV=production bundle exec rake assets:precompile
rake aborted!
ActiveRecord::NoDatabaseError: FATAL: database "xyz" does not exist
Run `$ bin/rake db:create db:migrate` to create your database
/Users/abc/.rvm/gems/ruby-2.1.2/gems/activerecord-4.1.6/lib/active_record/connection_adapters/postgresql_adapter.rb:898:in `rescue in connect'
/Users/abc/.rvm/gems/ruby-2.1.2/gems/activerecord-4.1.6/lib/active_record/connection_adapters/postgresql_adapter.rb:888:in `connect'
/Users/abc/.rvm/gems/ruby-2.1.2/gems/activerecord-4.1.6/lib/active_record/connection_adapters/postgresql_adapter.rb:568:in `initialize'
/Users/abc/.rvm/gems/ruby-2.1.2/gems/activerecord-4.1.6/lib/active_record/connection_adapters/postgresql_adapter.rb:41:in `new'
/Users/abc/.rvm/gems/ruby-2.1.2/gems/activerecord-4.1.6/lib/active_record/connection_adapters/postgresql_adapter.rb:41:in `postgresql_connection'
/Users/abc/.rvm/gems/ruby-2.1.2/gems/activerecord-4.1.6/lib/active_record/connection_adapters/abstract/connection_pool.rb:435:in `new_connection'
/Users/abc/.rvm/gems/ruby-2.1.2/gems/activerecord-4.1.6/lib/active_record/connection_adapters/abstract/connection_pool.rb:445:in `checkout_new_connection'
/Users/abc/.rvm/gems/ruby-2.1.2/gems/activerecord-4.1.6/lib/active_record/connection_adapters/abstract/connection_pool.rb:416:in `acquire_connection'
/Users/abc/.rvm/gems/ruby-2.1.2/gems/activerecord-4.1.6/lib/active_record/connection_adapters/abstract/connection_pool.rb:351:in `block in checkout'
/Users/abc/.rvm/gems/ruby-2.1.2/gems/activerecord-4.1.6/lib/active_record/connection_adapters/abstract/connection_pool.rb:350:in `checkout'
/Users/abc/.rvm/gems/ruby-2.1.2/gems/activerecord-4.1.6/lib/active_record/connection_adapters/abstract/connection_pool.rb:265:in `block in connection'
/Users/abc/.rvm/gems/ruby-2.1.2/gems/activerecord-4.1.6/lib/active_record/connection_adapters/abstract/connection_pool.rb:264:in `connection'
/Users/abc/.rvm/gems/ruby-2.1.2/gems/activerecord-4.1.6/lib/active_record/connection_adapters/abstract/connection_pool.rb:541:in `retrieve_connection'
/Users/abc/.rvm/gems/ruby-2.1.2/gems/activerecord-4.1.6/lib/active_record/connection_handling.rb:113:in `retrieve_connection'
/Users/abc/.rvm/gems/ruby-2.1.2/gems/activerecord-4.1.6/lib/active_record/connection_handling.rb:87:in `connection'
/Users/abc/.rvm/gems/ruby-2.1.2/gems/activerecord-4.1.6/lib/active_record/model_schema.rb:214:in `columns'
/Users/abc/.rvm/gems/ruby-2.1.2/gems/activerecord-4.1.6/lib/active_record/model_schema.rb:223:in `columns_hash'
/Users/abc/.rvm/gems/ruby-2.1.2/gems/activerecord-4.1.6/lib/active_record/relation/delegation.rb:48:in `columns_hash'
/Users/abc/.rvm/gems/ruby-2.1.2/gems/activerecord-4.1.6/lib/active_record/relation/calculations.rb:170:in `block in pluck'
/Users/abc/.rvm/gems/ruby-2.1.2/gems/activerecord-4.1.6/lib/active_record/relation/calculations.rb:169:in `map'
/Users/abc/.rvm/gems/ruby-2.1.2/gems/activerecord-4.1.6/lib/active_record/relation/calculations.rb:169:in `pluck'
/Users/abc/.rvm/gems/ruby-2.1.2/gems/activerecord-4.1.6/lib/active_record/querying.rb:14:in `pluck'
/Users/abc/workspace/xyz/app/admin/product.rb:31:in `block in <top (required)>'
/Users/abc/.rvm/gems/ruby-2.1.2/bundler/gems/activeadmin-f51d96dddb5e/lib/active_admin/dsl.rb:15:in `instance_exec'
/Users/abc/.rvm/gems/ruby-2.1.2/bundler/gems/activeadmin-f51d96dddb5e/lib/active_admin/dsl.rb:15:in `run_registration_block'
/Users/abc/.rvm/gems/ruby-2.1.2/bundler/gems/activeadmin-f51d96dddb5e/lib/active_admin/namespace.rb:223:in `parse_registration_block'
/Users/abc/.rvm/gems/ruby-2.1.2/bundler/gems/activeadmin-f51d96dddb5e/lib/active_admin/namespace.rb:48:in `register'
/Users/abc/.rvm/gems/ruby-2.1.2/bundler/gems/activeadmin-f51d96dddb5e/lib/active_admin/application.rb:136:in `register'
/Users/abc/.rvm/gems/ruby-2.1.2/bundler/gems/activeadmin-f51d96dddb5e/lib/active_admin.rb:75:in `register'
/Users/abc/workspace/xyz/app/admin/product.rb:1:in `<top (required)>'
/Users/abc/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.6/lib/active_support/dependencies.rb:241:in `load'
/Users/abc/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.6/lib/active_support/dependencies.rb:241:in `block in load'
/Users/abc/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.6/lib/active_support/dependencies.rb:232:in `load_dependency'
/Users/abc/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.6/lib/active_support/dependencies.rb:241:in `load'
/Users/abc/.rvm/gems/ruby-2.1.2/bundler/gems/activeadmin-f51d96dddb5e/lib/active_admin/application.rb:194:in `block in load'
/Users/abc/.rvm/gems/ruby-2.1.2/bundler/gems/activeadmin-f51d96dddb5e/lib/active_admin/error.rb:40:in `capture'
/Users/abc/.rvm/gems/ruby-2.1.2/bundler/gems/activeadmin-f51d96dddb5e/lib/active_admin/application.rb:194:in `load'
/Users/abc/.rvm/gems/ruby-2.1.2/bundler/gems/activeadmin-f51d96dddb5e/lib/active_admin/application.rb:186:in `block in load!'
/Users/abc/.rvm/gems/ruby-2.1.2/bundler/gems/activeadmin-f51d96dddb5e/lib/active_admin/application.rb:186:in `each'
/Users/abc/.rvm/gems/ruby-2.1.2/bundler/gems/activeadmin-f51d96dddb5e/lib/active_admin/application.rb:186:in `load!'
/Users/abc/.rvm/gems/ruby-2.1.2/bundler/gems/activeadmin-f51d96dddb5e/lib/active_admin/application.rb:208:in `routes'
/Users/abc/.rvm/gems/ruby-2.1.2/bundler/gems/activeadmin-f51d96dddb5e/lib/active_admin.rb:79:in `routes'
/Users/abc/workspace/xyz/config/routes.rb:3:in `block in <top (required)>'
/Users/abc/.rvm/gems/ruby-2.1.2/gems/actionpack-4.1.6/lib/action_dispatch/routing/route_set.rb:337:in `instance_exec'
/Users/abc/.rvm/gems/ruby-2.1.2/gems/actionpack-4.1.6/lib/action_dispatch/routing/route_set.rb:337:in `eval_block'
/Users/abc/.rvm/gems/ruby-2.1.2/gems/actionpack-4.1.6/lib/action_dispatch/routing/route_set.rb:315:in `draw'
/Users/abc/workspace/xyz/config/routes.rb:1:in `<top (required)>'
/Users/abc/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.6/lib/active_support/dependencies.rb:241:in `load'
/Users/abc/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.6/lib/active_support/dependencies.rb:241:in `block in load'
/Users/abc/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.6/lib/active_support/dependencies.rb:232:in `load_dependency'
/Users/abc/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.6/lib/active_support/dependencies.rb:241:in `load'
/Users/abc/.rvm/gems/ruby-2.1.2/gems/railties-4.1.6/lib/rails/application/routes_reloader.rb:40:in `block in load_paths'
/Users/abc/.rvm/gems/ruby-2.1.2/gems/railties-4.1.6/lib/rails/application/routes_reloader.rb:40:in `each'
/Users/abc/.rvm/gems/ruby-2.1.2/gems/railties-4.1.6/lib/rails/application/routes_reloader.rb:40:in `load_paths'
/Users/abc/.rvm/gems/ruby-2.1.2/gems/railties-4.1.6/lib/rails/application/routes_reloader.rb:16:in `reload!'
/Users/abc/.rvm/gems/ruby-2.1.2/gems/railties-4.1.6/lib/rails/application/routes_reloader.rb:26:in `block in updater'
/Users/abc/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.6/lib/active_support/file_update_checker.rb:75:in `call'
/Users/abc/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.6/lib/active_support/file_update_checker.rb:75:in `execute'
/Users/abc/.rvm/gems/ruby-2.1.2/gems/railties-4.1.6/lib/rails/application/routes_reloader.rb:27:in `updater'
/Users/abc/.rvm/gems/ruby-2.1.2/gems/railties-4.1.6/lib/rails/application/routes_reloader.rb:7:in `execute_if_updated'
/Users/abc/.rvm/gems/ruby-2.1.2/gems/railties-4.1.6/lib/rails/application/finisher.rb:71:in `block in <module:Finisher>'
/Users/abc/.rvm/gems/ruby-2.1.2/gems/railties-4.1.6/lib/rails/initializable.rb:30:in `instance_exec'
/Users/abc/.rvm/gems/ruby-2.1.2/gems/railties-4.1.6/lib/rails/initializable.rb:30:in `run'
/Users/abc/.rvm/gems/ruby-2.1.2/gems/railties-4.1.6/lib/rails/initializable.rb:55:in `block in run_initializers'
/Users/abc/.rvm/gems/ruby-2.1.2/gems/railties-4.1.6/lib/rails/initializable.rb:54:in `run_initializers'
/Users/abc/.rvm/gems/ruby-2.1.2/gems/railties-4.1.6/lib/rails/application.rb:300:in `initialize!'
/Users/abc/.rvm/gems/ruby-2.1.2/gems/railties-4.1.6/lib/rails/railtie.rb:194:in `public_send'
/Users/abc/.rvm/gems/ruby-2.1.2/gems/railties-4.1.6/lib/rails/railtie.rb:194:in `method_missing'
/Users/abc/workspace/xyz/config/environment.rb:5:in `<top (required)>'
/Users/abc/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.6/lib/active_support/dependencies.rb:247:in `require'
/Users/abc/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.6/lib/active_support/dependencies.rb:247:in `block in require'
/Users/abc/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.6/lib/active_support/dependencies.rb:232:in `load_dependency'
/Users/abc/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.6/lib/active_support/dependencies.rb:247:in `require'
/Users/abc/.rvm/gems/ruby-2.1.2/gems/railties-4.1.6/lib/rails/application.rb:276:in `require_environment!'
/Users/abc/.rvm/gems/ruby-2.1.2/gems/railties-4.1.6/lib/rails/application.rb:389:in `block in run_tasks_blocks'
/Users/abc/.rvm/gems/ruby-2.1.2/gems/sprockets-rails-2.2.2/lib/sprockets/rails/task.rb:64:in `block (2 levels) in define'
/Users/abc/.rvm/gems/ruby-2.1.2/bin/ruby_executable_hooks:15:in `eval'
/Users/abc/.rvm/gems/ruby-2.1.2/bin/ruby_executable_hooks:15:in `<main>'
PG::Error: FATAL: database "xyz" does not exist
Run `$ bin/rake db:create db:migrate` to create your database
/Users/abc/.rvm/gems/ruby-2.1.2/gems/activerecord-4.1.6/lib/active_record/connection_adapters/postgresql_adapter.rb:888:in `initialize'
/Users/abc/.rvm/gems/ruby-2.1.2/gems/activerecord-4.1.6/lib/active_record/connection_adapters/postgresql_adapter.rb:888:in `new'
/Users/abc/.rvm/gems/ruby-2.1.2/gems/activerecord-4.1.6/lib/active_record/connection_adapters/postgresql_adapter.rb:888:in `connect'
/Users/abc/.rvm/gems/ruby-2.1.2/gems/activerecord-4.1.6/lib/active_record/connection_adapters/postgresql_adapter.rb:568:in `initialize'
/Users/abc/.rvm/gems/ruby-2.1.2/gems/activerecord-4.1.6/lib/active_record/connection_adapters/postgresql_adapter.rb:41:in `new'
/Users/abc/.rvm/gems/ruby-2.1.2/gems/activerecord-4.1.6/lib/active_record/connection_adapters/postgresql_adapter.rb:41:in `postgresql_connection'
/Users/abc/.rvm/gems/ruby-2.1.2/gems/activerecord-4.1.6/lib/active_record/connection_adapters/abstract/connection_pool.rb:435:in `new_connection'
/Users/abc/.rvm/gems/ruby-2.1.2/gems/activerecord-4.1.6/lib/active_record/connection_adapters/abstract/connection_pool.rb:445:in `checkout_new_connection'
/Users/abc/.rvm/gems/ruby-2.1.2/gems/activerecord-4.1.6/lib/active_record/connection_adapters/abstract/connection_pool.rb:416:in `acquire_connection'
/Users/abc/.rvm/gems/ruby-2.1.2/gems/activerecord-4.1.6/lib/active_record/connection_adapters/abstract/connection_pool.rb:351:in `block in checkout'
/Users/abc/.rvm/gems/ruby-2.1.2/gems/activerecord-4.1.6/lib/active_record/connection_adapters/abstract/connection_pool.rb:350:in `checkout'
/Users/abc/.rvm/gems/ruby-2.1.2/gems/activerecord-4.1.6/lib/active_record/connection_adapters/abstract/connection_pool.rb:265:in `block in connection'
/Users/abc/.rvm/gems/ruby-2.1.2/gems/activerecord-4.1.6/lib/active_record/connection_adapters/abstract/connection_pool.rb:264:in `connection'
/Users/abc/.rvm/gems/ruby-2.1.2/gems/activerecord-4.1.6/lib/active_record/connection_adapters/abstract/connection_pool.rb:541:in `retrieve_connection'
/Users/abc/.rvm/gems/ruby-2.1.2/gems/activerecord-4.1.6/lib/active_record/connection_handling.rb:113:in `retrieve_connection'
/Users/abc/.rvm/gems/ruby-2.1.2/gems/activerecord-4.1.6/lib/active_record/connection_handling.rb:87:in `connection'
/Users/abc/.rvm/gems/ruby-2.1.2/gems/activerecord-4.1.6/lib/active_record/model_schema.rb:214:in `columns'
/Users/abc/.rvm/gems/ruby-2.1.2/gems/activerecord-4.1.6/lib/active_record/model_schema.rb:223:in `columns_hash'
/Users/abc/.rvm/gems/ruby-2.1.2/gems/activerecord-4.1.6/lib/active_record/relation/delegation.rb:48:in `columns_hash'
/Users/abc/.rvm/gems/ruby-2.1.2/gems/activerecord-4.1.6/lib/active_record/relation/calculations.rb:170:in `block in pluck'
/Users/abc/.rvm/gems/ruby-2.1.2/gems/activerecord-4.1.6/lib/active_record/relation/calculations.rb:169:in `map'
/Users/abc/.rvm/gems/ruby-2.1.2/gems/activerecord-4.1.6/lib/active_record/relation/calculations.rb:169:in `pluck'
/Users/abc/.rvm/gems/ruby-2.1.2/gems/activerecord-4.1.6/lib/active_record/querying.rb:14:in `pluck'
/Users/abc/workspace/xyz/app/admin/product.rb:31:in `block in <top (required)>'
/Users/abc/.rvm/gems/ruby-2.1.2/bundler/gems/activeadmin-f51d96dddb5e/lib/active_admin/dsl.rb:15:in `instance_exec'
/Users/abc/.rvm/gems/ruby-2.1.2/bundler/gems/activeadmin-f51d96dddb5e/lib/active_admin/dsl.rb:15:in `run_registration_block'
/Users/abc/.rvm/gems/ruby-2.1.2/bundler/gems/activeadmin-f51d96dddb5e/lib/active_admin/namespace.rb:223:in `parse_registration_block'
/Users/abc/.rvm/gems/ruby-2.1.2/bundler/gems/activeadmin-f51d96dddb5e/lib/active_admin/namespace.rb:48:in `register'
/Users/abc/.rvm/gems/ruby-2.1.2/bundler/gems/activeadmin-f51d96dddb5e/lib/active_admin/application.rb:136:in `register'
/Users/abc/.rvm/gems/ruby-2.1.2/bundler/gems/activeadmin-f51d96dddb5e/lib/active_admin.rb:75:in `register'
/Users/abc/workspace/xyz/app/admin/product.rb:1:in `<top (required)>'
/Users/abc/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.6/lib/active_support/dependencies.rb:241:in `load'
/Users/abc/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.6/lib/active_support/dependencies.rb:241:in `block in load'
/Users/abc/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.6/lib/active_support/dependencies.rb:232:in `load_dependency'
/Users/abc/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.6/lib/active_support/dependencies.rb:241:in `load'
/Users/abc/.rvm/gems/ruby-2.1.2/bundler/gems/activeadmin-f51d96dddb5e/lib/active_admin/application.rb:194:in `block in load'
/Users/abc/.rvm/gems/ruby-2.1.2/bundler/gems/activeadmin-f51d96dddb5e/lib/active_admin/error.rb:40:in `capture'
/Users/abc/.rvm/gems/ruby-2.1.2/bundler/gems/activeadmin-f51d96dddb5e/lib/active_admin/application.rb:194:in `load'
/Users/abc/.rvm/gems/ruby-2.1.2/bundler/gems/activeadmin-f51d96dddb5e/lib/active_admin/application.rb:186:in `block in load!'
/Users/abc/.rvm/gems/ruby-2.1.2/bundler/gems/activeadmin-f51d96dddb5e/lib/active_admin/application.rb:186:in `each'
/Users/abc/.rvm/gems/ruby-2.1.2/bundler/gems/activeadmin-f51d96dddb5e/lib/active_admin/application.rb:186:in `load!'
/Users/abc/.rvm/gems/ruby-2.1.2/bundler/gems/activeadmin-f51d96dddb5e/lib/active_admin/application.rb:208:in `routes'
/Users/abc/.rvm/gems/ruby-2.1.2/bundler/gems/activeadmin-f51d96dddb5e/lib/active_admin.rb:79:in `routes'
/Users/abc/workspace/xyz/config/routes.rb:3:in `block in <top (required)>'
/Users/abc/.rvm/gems/ruby-2.1.2/gems/actionpack-4.1.6/lib/action_dispatch/routing/route_set.rb:337:in `instance_exec'
/Users/abc/.rvm/gems/ruby-2.1.2/gems/actionpack-4.1.6/lib/action_dispatch/routing/route_set.rb:337:in `eval_block'
/Users/abc/.rvm/gems/ruby-2.1.2/gems/actionpack-4.1.6/lib/action_dispatch/routing/route_set.rb:315:in `draw'
/Users/abc/workspace/xyz/config/routes.rb:1:in `<top (required)>'
/Users/abc/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.6/lib/active_support/dependencies.rb:241:in `load'
/Users/abc/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.6/lib/active_support/dependencies.rb:241:in `block in load'
/Users/abc/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.6/lib/active_support/dependencies.rb:232:in `load_dependency'
/Users/abc/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.6/lib/active_support/dependencies.rb:241:in `load'
/Users/abc/.rvm/gems/ruby-2.1.2/gems/railties-4.1.6/lib/rails/application/routes_reloader.rb:40:in `block in load_paths'
/Users/abc/.rvm/gems/ruby-2.1.2/gems/railties-4.1.6/lib/rails/application/routes_reloader.rb:40:in `each'
/Users/abc/.rvm/gems/ruby-2.1.2/gems/railties-4.1.6/lib/rails/application/routes_reloader.rb:40:in `load_paths'
/Users/abc/.rvm/gems/ruby-2.1.2/gems/railties-4.1.6/lib/rails/application/routes_reloader.rb:16:in `reload!'
/Users/abc/.rvm/gems/ruby-2.1.2/gems/railties-4.1.6/lib/rails/application/routes_reloader.rb:26:in `block in updater'
/Users/abc/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.6/lib/active_support/file_update_checker.rb:75:in `call'
/Users/abc/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.6/lib/active_support/file_update_checker.rb:75:in `execute'
/Users/abc/.rvm/gems/ruby-2.1.2/gems/railties-4.1.6/lib/rails/application/routes_reloader.rb:27:in `updater'
/Users/abc/.rvm/gems/ruby-2.1.2/gems/railties-4.1.6/lib/rails/application/routes_reloader.rb:7:in `execute_if_updated'
/Users/abc/.rvm/gems/ruby-2.1.2/gems/railties-4.1.6/lib/rails/application/finisher.rb:71:in `block in <module:Finisher>'
/Users/abc/.rvm/gems/ruby-2.1.2/gems/railties-4.1.6/lib/rails/initializable.rb:30:in `instance_exec'
/Users/abc/.rvm/gems/ruby-2.1.2/gems/railties-4.1.6/lib/rails/initializable.rb:30:in `run'
/Users/abc/.rvm/gems/ruby-2.1.2/gems/railties-4.1.6/lib/rails/initializable.rb:55:in `block in run_initializers'
/Users/abc/.rvm/gems/ruby-2.1.2/gems/railties-4.1.6/lib/rails/initializable.rb:54:in `run_initializers'
/Users/abc/.rvm/gems/ruby-2.1.2/gems/railties-4.1.6/lib/rails/application.rb:300:in `initialize!'
/Users/abc/.rvm/gems/ruby-2.1.2/gems/railties-4.1.6/lib/rails/railtie.rb:194:in `public_send'
/Users/abc/.rvm/gems/ruby-2.1.2/gems/railties-4.1.6/lib/rails/railtie.rb:194:in `method_missing'
/Users/abc/workspace/xyz/config/environment.rb:5:in `<top (required)>'
/Users/abc/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.6/lib/active_support/dependencies.rb:247:in `require'
/Users/abc/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.6/lib/active_support/dependencies.rb:247:in `block in require'
/Users/abc/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.6/lib/active_support/dependencies.rb:232:in `load_dependency'
/Users/abc/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.6/lib/active_support/dependencies.rb:247:in `require'
/Users/abc/.rvm/gems/ruby-2.1.2/gems/railties-4.1.6/lib/rails/application.rb:276:in `require_environment!'
/Users/abc/.rvm/gems/ruby-2.1.2/gems/railties-4.1.6/lib/rails/application.rb:389:in `block in run_tasks_blocks'
/Users/abc/.rvm/gems/ruby-2.1.2/gems/sprockets-rails-2.2.2/lib/sprockets/rails/task.rb:64:in `block (2 levels) in define'
/Users/abc/.rvm/gems/ruby-2.1.2/bin/ruby_executable_hooks:15:in `eval'
/Users/abc/.rvm/gems/ruby-2.1.2/bin/ruby_executable_hooks:15:in `<main>'
Tasks: TOP => environment
(See full trace by running task with --trace)
【问题讨论】:
您的资产中似乎有对app/admin/product.rb
的引用,但尚未创建数据库。您是否已经在生产环境中运行了 rake db:create db:migrate
?
我之前已经部署到 Heroku,所以是的,我有一个生产数据库。但我是在本地做这个预编译,所以这不应该适用?
我不相信我故意在资产中引用了该文件,关于如何追踪它的想法?这个文件不是新的(只是发生了很大的变化),因为我上次尝试部署(并且预编译工作正常)。
如果您在开发机器上编译资产以用于生产,并且在该过程中它正在访问数据库,那么它期望在production
下配置的数据库可用。您的开发机器上是否存在该生产数据库?如果是,是否填充了所需的种子数据?
【参考方案1】:
看起来我太专注于错误的最后几行,并尝试了我在引用类似文本的页面上阅读的所有内容(以及多个 Heroku 环境之间的不同结果让我更加失望)并跳过了相关 product.rb会指出我的问题的行。我在为该特定页面设置范围和过滤器时有数据库引用,但没有意识到这些会影响资产的生成。
Product.pluck(:type).uniq.sort.each do |p|
scope(p) |scope| scope.where(type: p)
end
filter :type, as: :select, collection: Product.pluck(:type).uniq.sort
在注释掉这些行之后,预编译再次正常工作。
=====
一旦我知道要搜索什么,就找到了:https://github.com/activeadmin/activeadmin/issues/2781
因此更好的解决方案是将其添加到 routes.rb:
ActiveAdmin.routes(self) unless ARGV.grep(/assets:(precompile|clean)/).any?
【讨论】:
以上是关于Rails 4 - 生产资产:预编译导致 ActiveRecord::NoDatabaseError: FATAL: database does not exist的主要内容,如果未能解决你的问题,请参考以下文章
Rails 3.1 资产管道 - 为啥我的图像没有为生产进行预编译?
RAILS_ENV=生产轨道资产:预编译不适用于 RSpec