2012-01-25 8 views
27

Estoy intentando depurar por qué mi aplicación está intentando conectarse a mi base de datos cuando ejecuto rake assets:precompile --trace.activos de rake: precompilación que intenta conectarse a la base de datos

Probablemente me falta algo en la pila ... ¿alguien ve la línea correspondiente?

DEPRECATION WARNING: The InstanceMethods module inside ActiveSupport::Concern will be no longer included automatically. Please define instance methods directly in ActionController::Base instead. (called from <top (required)> at /Users/Kyle/Desktop/skateparks-web/config/application.rb:4) 
** Invoke assets:precompile (first_time) 
** Execute assets:precompile 
/Users/Kyle/.rvm/rubies/ruby-1.9.2-p290/bin/ruby /Users/Kyle/.rvm/gems/[email protected]/bin/rake assets:precompile:all RAILS_ENV=production RAILS_GROUPS=assets --trace 
DEPRECATION WARNING: The InstanceMethods module inside ActiveSupport::Concern will be no longer included automatically. Please define instance methods directly in ActionController::Base instead. (called from <top (required)> at /Users/Kyle/Desktop/skateparks-web/config/application.rb:4) 
** Invoke assets:precompile:all (first_time) 
** Execute assets:precompile:all 
** Invoke assets:precompile:primary (first_time) 
** Invoke assets:environment (first_time) 
** Execute assets:environment 
** Invoke environment (first_time) 
** Execute environment 
rake aborted! 
FATAL: database "skateparks_production" does not exist 
/Users/Kyle/.rvm/gems/[email protected]/gems/activerecord-3.2.0/lib/active_record/connection_adapters/postgresql_adapter.rb:1161:in `initialize' 
/Users/Kyle/.rvm/gems/[email protected]/gems/activerecord-3.2.0/lib/active_record/connection_adapters/postgresql_adapter.rb:1161:in `new' 
/Users/Kyle/.rvm/gems/[email protected]/gems/activerecord-3.2.0/lib/active_record/connection_adapters/postgresql_adapter.rb:1161:in `connect' 
/Users/Kyle/.rvm/gems/[email protected]/gems/activerecord-3.2.0/lib/active_record/connection_adapters/postgresql_adapter.rb:316:in `initialize' 
/Users/Kyle/.rvm/gems/[email protected]/gems/activerecord-3.2.0/lib/active_record/connection_adapters/postgresql_adapter.rb:27:in `new' 
/Users/Kyle/.rvm/gems/[email protected]/gems/activerecord-3.2.0/lib/active_record/connection_adapters/postgresql_adapter.rb:27:in `postgresql_connection' 
/Users/Kyle/.rvm/gems/[email protected]/gems/activerecord-3.2.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:277:in `new_connection' 
/Users/Kyle/.rvm/gems/[email protected]/gems/activerecord-3.2.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:287:in `checkout_new_connection' 
/Users/Kyle/.rvm/gems/[email protected]/gems/activerecord-3.2.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:235:in `block (2 levels) in checkout' 
/Users/Kyle/.rvm/gems/[email protected]/gems/activerecord-3.2.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:230:in `loop' 
/Users/Kyle/.rvm/gems/[email protected]/gems/activerecord-3.2.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:230:in `block in checkout' 
/Users/Kyle/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/monitor.rb:201:in `mon_synchronize' 
/Users/Kyle/.rvm/gems/[email protected]/gems/activerecord-3.2.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:229:in `checkout' 
/Users/Kyle/.rvm/gems/[email protected]/gems/activerecord-3.2.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:95:in `connection' 
/Users/Kyle/.rvm/gems/[email protected]/gems/activerecord-3.2.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:374:in `retrieve_connection' 
/Users/Kyle/.rvm/gems/[email protected]/gems/activerecord-3.2.0/lib/active_record/connection_adapters/abstract/connection_specification.rb:168:in `retrieve_connection' 
/Users/Kyle/.rvm/gems/[email protected]/gems/activerecord-3.2.0/lib/active_record/connection_adapters/abstract/connection_specification.rb:142:in `connection' 
/Users/Kyle/.rvm/gems/[email protected]/gems/activerecord-3.2.0/lib/active_record/model_schema.rb:308:in `clear_cache!' 
/Users/Kyle/.rvm/gems/[email protected]/gems/activerecord-3.2.0/lib/active_record/railtie.rb:91:in `block (2 levels) in <class:Railtie>' 
/Users/Kyle/.rvm/gems/[email protected]/gems/activesupport-3.2.0/lib/active_support/callbacks.rb:418:in `_run__2041913228368879189__prepare__1991931652306887621__callbacks' 
/Users/Kyle/.rvm/gems/[email protected]/gems/activesupport-3.2.0/lib/active_support/callbacks.rb:405:in `__run_callback' 
/Users/Kyle/.rvm/gems/[email protected]/gems/activesupport-3.2.0/lib/active_support/callbacks.rb:385:in `_run_prepare_callbacks' 
/Users/Kyle/.rvm/gems/[email protected]/gems/activesupport-3.2.0/lib/active_support/callbacks.rb:81:in `run_callbacks' 
/Users/Kyle/.rvm/gems/[email protected]/gems/actionpack-3.2.0/lib/action_dispatch/middleware/reloader.rb:74:in `prepare!' 
/Users/Kyle/.rvm/gems/[email protected]/gems/actionpack-3.2.0/lib/action_dispatch/middleware/reloader.rb:48:in `prepare!' 
/Users/Kyle/.rvm/gems/[email protected]/gems/railties-3.2.0/lib/rails/application/finisher.rb:48:in `block in <module:Finisher>' 
/Users/Kyle/.rvm/gems/[email protected]/gems/railties-3.2.0/lib/rails/initializable.rb:30:in `instance_exec' 
/Users/Kyle/.rvm/gems/[email protected]/gems/railties-3.2.0/lib/rails/initializable.rb:30:in `run' 
/Users/Kyle/.rvm/gems/[email protected]/gems/railties-3.2.0/lib/rails/initializable.rb:55:in `block in run_initializers' 
/Users/Kyle/.rvm/gems/[email protected]/gems/railties-3.2.0/lib/rails/initializable.rb:54:in `each' 
/Users/Kyle/.rvm/gems/[email protected]/gems/railties-3.2.0/lib/rails/initializable.rb:54:in `run_initializers' 
/Users/Kyle/.rvm/gems/[email protected]/gems/railties-3.2.0/lib/rails/application.rb:136:in `initialize!' 
/Users/Kyle/.rvm/gems/[email protected]/gems/railties-3.2.0/lib/rails/railtie/configurable.rb:30:in `method_missing' 
/Users/Kyle/Desktop/skateparks-web/config/environment.rb:5:in `<top (required)>' 
/Users/Kyle/.rvm/gems/[email protected]/gems/activesupport-3.2.0/lib/active_support/dependencies.rb:251:in `require' 
/Users/Kyle/.rvm/gems/[email protected]/gems/activesupport-3.2.0/lib/active_support/dependencies.rb:251:in `block in require' 
/Users/Kyle/.rvm/gems/[email protected]/gems/activesupport-3.2.0/lib/active_support/dependencies.rb:236:in `load_dependency' 
/Users/Kyle/.rvm/gems/[email protected]/gems/activesupport-3.2.0/lib/active_support/dependencies.rb:251:in `require' 
/Users/Kyle/.rvm/gems/[email protected]/gems/railties-3.2.0/lib/rails/application.rb:103:in `require_environment!' 
/Users/Kyle/.rvm/gems/[email protected]/gems/railties-3.2.0/lib/rails/application.rb:292:in `block (2 levels) in initialize_tasks' 
/Users/Kyle/.rvm/gems/[email protected]/gems/rake-0.9.2/lib/rake/task.rb:205:in `call' 
/Users/Kyle/.rvm/gems/[email protected]/gems/rake-0.9.2/lib/rake/task.rb:205:in `block in execute' 
/Users/Kyle/.rvm/gems/[email protected]/gems/rake-0.9.2/lib/rake/task.rb:200:in `each' 
/Users/Kyle/.rvm/gems/[email protected]/gems/rake-0.9.2/lib/rake/task.rb:200:in `execute' 
/Users/Kyle/.rvm/gems/[email protected]/gems/rake-0.9.2/lib/rake/task.rb:158:in `block in invoke_with_call_chain' 
/Users/Kyle/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/monitor.rb:201:in `mon_synchronize' 
/Users/Kyle/.rvm/gems/[email protected]/gems/rake-0.9.2/lib/rake/task.rb:151:in `invoke_with_call_chain' 
/Users/Kyle/.rvm/gems/[email protected]/gems/rake-0.9.2/lib/rake/task.rb:144:in `invoke' 
/Users/Kyle/.rvm/gems/[email protected]/gems/actionpack-3.2.0/lib/sprockets/assets.rake:89:in `block (2 levels) in <top (required)>' 
/Users/Kyle/.rvm/gems/[email protected]/gems/rake-0.9.2/lib/rake/task.rb:205:in `call' 
/Users/Kyle/.rvm/gems/[email protected]/gems/rake-0.9.2/lib/rake/task.rb:205:in `block in execute' 
/Users/Kyle/.rvm/gems/[email protected]/gems/rake-0.9.2/lib/rake/task.rb:200:in `each' 
/Users/Kyle/.rvm/gems/[email protected]/gems/rake-0.9.2/lib/rake/task.rb:200:in `execute' 
/Users/Kyle/.rvm/gems/[email protected]/gems/rake-0.9.2/lib/rake/task.rb:158:in `block in invoke_with_call_chain' 
/Users/Kyle/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/monitor.rb:201:in `mon_synchronize' 
/Users/Kyle/.rvm/gems/[email protected]/gems/rake-0.9.2/lib/rake/task.rb:151:in `invoke_with_call_chain' 
/Users/Kyle/.rvm/gems/[email protected]/gems/rake-0.9.2/lib/rake/task.rb:176:in `block in invoke_prerequisites' 
/Users/Kyle/.rvm/gems/[email protected]/gems/rake-0.9.2/lib/rake/task.rb:174:in `each' 
/Users/Kyle/.rvm/gems/[email protected]/gems/rake-0.9.2/lib/rake/task.rb:174:in `invoke_prerequisites' 
/Users/Kyle/.rvm/gems/[email protected]/gems/rake-0.9.2/lib/rake/task.rb:157:in `block in invoke_with_call_chain' 
/Users/Kyle/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/monitor.rb:201:in `mon_synchronize' 
/Users/Kyle/.rvm/gems/[email protected]/gems/rake-0.9.2/lib/rake/task.rb:151:in `invoke_with_call_chain' 
/Users/Kyle/.rvm/gems/[email protected]/gems/rake-0.9.2/lib/rake/task.rb:144:in `invoke' 
/Users/Kyle/.rvm/gems/[email protected]/gems/actionpack-3.2.0/lib/sprockets/assets.rake:56:in `block (3 levels) in <top (required)>' 
/Users/Kyle/.rvm/gems/[email protected]/gems/rake-0.9.2/lib/rake/task.rb:205:in `call' 
/Users/Kyle/.rvm/gems/[email protected]/gems/rake-0.9.2/lib/rake/task.rb:205:in `block in execute' 
/Users/Kyle/.rvm/gems/[email protected]/gems/rake-0.9.2/lib/rake/task.rb:200:in `each' 
/Users/Kyle/.rvm/gems/[email protected]/gems/rake-0.9.2/lib/rake/task.rb:200:in `execute' 
/Users/Kyle/.rvm/gems/[email protected]/gems/rake-0.9.2/lib/rake/task.rb:158:in `block in invoke_with_call_chain' 
/Users/Kyle/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/monitor.rb:201:in `mon_synchronize' 
/Users/Kyle/.rvm/gems/[email protected]/gems/rake-0.9.2/lib/rake/task.rb:151:in `invoke_with_call_chain' 
/Users/Kyle/.rvm/gems/[email protected]/gems/rake-0.9.2/lib/rake/task.rb:144:in `invoke' 
/Users/Kyle/.rvm/gems/[email protected]/gems/rake-0.9.2/lib/rake/application.rb:112:in `invoke_task' 
/Users/Kyle/.rvm/gems/[email protected]/gems/rake-0.9.2/lib/rake/application.rb:90:in `block (2 levels) in top_level' 
/Users/Kyle/.rvm/gems/[email protected]/gems/rake-0.9.2/lib/rake/application.rb:90:in `each' 
/Users/Kyle/.rvm/gems/[email protected]/gems/rake-0.9.2/lib/rake/application.rb:90:in `block in top_level' 
/Users/Kyle/.rvm/gems/[email protected]/gems/rake-0.9.2/lib/rake/application.rb:129:in `standard_exception_handling' 
/Users/Kyle/.rvm/gems/[email protected]/gems/rake-0.9.2/lib/rake/application.rb:84:in `top_level' 
/Users/Kyle/.rvm/gems/[email protected]/gems/rake-0.9.2/lib/rake/application.rb:62:in `block in run' 
/Users/Kyle/.rvm/gems/[email protected]/gems/rake-0.9.2/lib/rake/application.rb:129:in `standard_exception_handling' 
/Users/Kyle/.rvm/gems/[email protected]/gems/rake-0.9.2/lib/rake/application.rb:59:in `run' 
/Users/Kyle/.rvm/gems/[email protected]/gems/rake-0.9.2/bin/rake:32:in `<top (required)>' 
/Users/Kyle/.rvm/gems/[email protected]/bin/rake:19:in `load' 
/Users/Kyle/.rvm/gems/[email protected]/bin/rake:19:in `<main>' 
Tasks: TOP => environment 
rake aborted! 
Command failed with status (1): [/Users/Kyle/.rvm/rubies/ruby-1.9.2-p290/bi...] 
/Users/Kyle/.rvm/gems/[email protected]/gems/rake-0.9.2/lib/rake/file_utils.rb:53:in `block in create_shell_runner' 
/Users/Kyle/.rvm/gems/[email protected]/gems/rake-0.9.2/lib/rake/file_utils.rb:45:in `call' 
/Users/Kyle/.rvm/gems/[email protected]/gems/rake-0.9.2/lib/rake/file_utils.rb:45:in `sh' 
/Users/Kyle/.rvm/gems/[email protected]/gems/rake-0.9.2/lib/rake/file_utils_ext.rb:36:in `sh' 
/Users/Kyle/.rvm/gems/[email protected]/gems/rake-0.9.2/lib/rake/file_utils.rb:78:in `ruby' 
/Users/Kyle/.rvm/gems/[email protected]/gems/rake-0.9.2/lib/rake/file_utils_ext.rb:36:in `ruby' 
/Users/Kyle/.rvm/gems/[email protected]/gems/actionpack-3.2.0/lib/sprockets/assets.rake:9:in `ruby_rake_task' 
/Users/Kyle/.rvm/gems/[email protected]/gems/actionpack-3.2.0/lib/sprockets/assets.rake:17:in `invoke_or_reboot_rake_task' 
/Users/Kyle/.rvm/gems/[email protected]/gems/actionpack-3.2.0/lib/sprockets/assets.rake:25:in `block (2 levels) in <top (required)>' 
/Users/Kyle/.rvm/gems/[email protected]/gems/rake-0.9.2/lib/rake/task.rb:205:in `call' 
/Users/Kyle/.rvm/gems/[email protected]/gems/rake-0.9.2/lib/rake/task.rb:205:in `block in execute' 
/Users/Kyle/.rvm/gems/[email protected]/gems/rake-0.9.2/lib/rake/task.rb:200:in `each' 
/Users/Kyle/.rvm/gems/[email protected]/gems/rake-0.9.2/lib/rake/task.rb:200:in `execute' 
/Users/Kyle/.rvm/gems/[email protected]/gems/rake-0.9.2/lib/rake/task.rb:158:in `block in invoke_with_call_chain' 
/Users/Kyle/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/monitor.rb:201:in `mon_synchronize' 
/Users/Kyle/.rvm/gems/[email protected]/gems/rake-0.9.2/lib/rake/task.rb:151:in `invoke_with_call_chain' 
/Users/Kyle/.rvm/gems/[email protected]/gems/rake-0.9.2/lib/rake/task.rb:144:in `invoke' 
/Users/Kyle/.rvm/gems/[email protected]/gems/rake-0.9.2/lib/rake/application.rb:112:in `invoke_task' 
/Users/Kyle/.rvm/gems/[email protected]/gems/rake-0.9.2/lib/rake/application.rb:90:in `block (2 levels) in top_level' 
/Users/Kyle/.rvm/gems/[email protected]/gems/rake-0.9.2/lib/rake/application.rb:90:in `each' 
/Users/Kyle/.rvm/gems/[email protected]/gems/rake-0.9.2/lib/rake/application.rb:90:in `block in top_level' 
/Users/Kyle/.rvm/gems/[email protected]/gems/rake-0.9.2/lib/rake/application.rb:129:in `standard_exception_handling' 
/Users/Kyle/.rvm/gems/[email protected]/gems/rake-0.9.2/lib/rake/application.rb:84:in `top_level' 
/Users/Kyle/.rvm/gems/[email protected]/gems/rake-0.9.2/lib/rake/application.rb:62:in `block in run' 
/Users/Kyle/.rvm/gems/[email protected]/gems/rake-0.9.2/lib/rake/application.rb:129:in `standard_exception_handling' 
/Users/Kyle/.rvm/gems/[email protected]/gems/rake-0.9.2/lib/rake/application.rb:59:in `run' 
/Users/Kyle/.rvm/gems/[email protected]/gems/rake-0.9.2/bin/rake:32:in `<top (required)>' 
/Users/Kyle/.rvm/gems/[email protected]/bin/rake:19:in `load' 
/Users/Kyle/.rvm/gems/[email protected]/bin/rake:19:in `<main>' 
Tasks: TOP => assets:precompile 

Respuesta

36

rake assets:precompile inicializa su aplicación por defecto, el cual incluye la conexión a la base de datos.

Dentro config/application.rb puede agregar esto, pero consulte el siguiente enlace para las advertencias al respecto:

config.assets.initialize_on_precompile = false 

Rails Guide on Precompiling Assets

+10

Esto ya no funciona en Rails 4. –

+0

El enlace de arriba va a los últimos documentos ... (y la advertencia no estaba allí). Para la versión de documentos de Rails 3.2 con la advertencia, vaya aquí: http://guides.rubyonrails.org/v3.2.13/asset_pipeline.html#precompiling-assets – Nick

+0

@ KARASZIIstván esto parece estar funcionando en Rails 4.2.4. Creo que ha sido arreglado. – mawaldne

4

Si tiene sentido en su situación, puede elegir contra qué entorno assets:precompile debería funcionar , con el siguiente comando:

rake assets:precompile:all RAILS_ENV=development RAILS_GROUPS=assets 

Esto tiene sentido para mi implementación porque generalmente:

  1. hago rastrillo para genera activos en mi máquina de desarrollo (debido a la memoria de mis VPS es de alguna manera limitado)
  2. que comprimir todo la aplicación con los activos generados en público/activos
  3. puedo transferir el zip a la vps ans descomprimir el paquete allí

Espero que ayude.

+0

¡Gracias! Esto también es perfecto cuando se usa Cells 4 con activos agrupados. Cells agrega directorios al AP a través de una variable, pero necesita que se carguen los archivos de clase de celda, y al desactivar initialize_on_precompile se rompe esto. – apotonick

1

Tuve el mismo problema. Después de actualizar los piñones a la versión 3, siempre que trataba precompilar los activos a nivel local (desarrollo), sin embargo el uso de la configuración del entorno de producción, tuve este error:

rake aborted! Gem::LoadError: Specified 'postgresql' for database adapter, but the gem is not loaded. Add joya 'pg' to your Gemfile (and ensure its version is at the minimum required by ActiveRecord).

Porque en mi local (desarrollo) Yo uso MySQL y en el servidor (producción), uso Postgres.

La respuesta marcada como resuelta no funciona para mí, porque config.assets.initialize_on_precompile no está disponible en Rails 4.2.1.

de resolver, seguí 3 pasos simples:

  1. En su Gemfile, añadir: gem "activerecord-nulldb-adapter"
  2. En database.yml, cambie el adaptador de la siguiente manera:

    production:

    adapter: <%= ENV['DB_ADAPTER'] ||= 'postgresql' %> 
    
  3. Para compilar sus activos de producción loca lly. correr en su terminal: DB_ADAPTER=nulldb RAILS_ENV=production rake assets:precompile

Esta solución resuelve a mí y yo sawyed here.

Cuestiones relacionadas