rails console工作但rails服务器无法正常工作

时间:2015-01-12 00:16:23

标签: database ruby-on-rails-4 rails-console

嗨,我遇到了一个对我没有意义的问题。

在我的托管服务器上,我有一个我想要运行的rails应用程序。我可以使用capistrano部署应用程序。我也可以毫无问题地运行bundle exec rails console production。但是当我尝试运行bundle exec rails server时,它会退出并出现以下错误。

/home/asavale1/rails_apps/dejalearn/shared/bundle/ruby/2.1.0/gems/activerecord-4.0.2/lib/active_record/connection_adapters/connection_specification.rb:52:in `resolve_hash_connection': database configuration does not specify adapter (ActiveRecord::AdapterNotSpecified)
    from /home/asavale1/rails_apps/dejalearn/shared/bundle/ruby/2.1.0/gems/activerecord-4.0.2/lib/active_record/connection_adapters/connection_specification.rb:46:in `resolve_string_connection'
    from /home/asavale1/rails_apps/dejalearn/shared/bundle/ruby/2.1.0/gems/activerecord-4.0.2/lib/active_record/connection_adapters/connection_specification.rb:30:in `spec'
    from /home/asavale1/rails_apps/dejalearn/shared/bundle/ruby/2.1.0/gems/activerecord-4.0.2/lib/active_record/connection_handling.rb:39:in `establish_connection'
    from /home/asavale1/rails_apps/dejalearn/shared/bundle/ruby/2.1.0/gems/activerecord-4.0.2/lib/active_record/railtie.rb:176:in `block (2 levels) in <class:Railtie>'
    from /home/asavale1/rails_apps/dejalearn/shared/bundle/ruby/2.1.0/gems/activesupport-4.0.2/lib/active_support/lazy_load_hooks.rb:38:in `instance_eval'
    from /home/asavale1/rails_apps/dejalearn/shared/bundle/ruby/2.1.0/gems/activesupport-4.0.2/lib/active_support/lazy_load_hooks.rb:38:in `execute_hook'
    from /home/asavale1/rails_apps/dejalearn/shared/bundle/ruby/2.1.0/gems/activesupport-4.0.2/lib/active_support/lazy_load_hooks.rb:45:in `block in run_load_hooks'
    from /home/asavale1/rails_apps/dejalearn/shared/bundle/ruby/2.1.0/gems/activesupport-4.0.2/lib/active_support/lazy_load_hooks.rb:44:in `each'
    from /home/asavale1/rails_apps/dejalearn/shared/bundle/ruby/2.1.0/gems/activesupport-4.0.2/lib/active_support/lazy_load_hooks.rb:44:in `run_load_hooks'
    from /home/asavale1/rails_apps/dejalearn/shared/bundle/ruby/2.1.0/gems/activerecord-4.0.2/lib/active_record/base.rb:322:in `<module:ActiveRecord>'
    from /home/asavale1/rails_apps/dejalearn/shared/bundle/ruby/2.1.0/gems/activerecord-4.0.2/lib/active_record/base.rb:22:in `<top (required)>'
    from /home/asavale1/rails_apps/dejalearn/shared/bundle/ruby/2.1.0/gems/devise-3.2.4/lib/devise/orm/active_record.rb:3:in `<top (required)>'
    from /home/asavale1/rails_apps/dejalearn/shared/bundle/ruby/2.1.0/gems/activesupport-4.0.2/lib/active_support/dependencies.rb:229:in `require'
    from /home/asavale1/rails_apps/dejalearn/shared/bundle/ruby/2.1.0/gems/activesupport-4.0.2/lib/active_support/dependencies.rb:229:in `block in require'
    from /home/asavale1/rails_apps/dejalearn/shared/bundle/ruby/2.1.0/gems/activesupport-4.0.2/lib/active_support/dependencies.rb:214:in `load_dependency'
    from /home/asavale1/rails_apps/dejalearn/shared/bundle/ruby/2.1.0/gems/activesupport-4.0.2/lib/active_support/dependencies.rb:229:in `require'
    from /home/asavale1/rails_apps/dejalearn/releases/20150110214352/config/initializers/devise.rb:22:in `block in <top (required)>'
    from /home/asavale1/rails_apps/dejalearn/shared/bundle/ruby/2.1.0/gems/devise-3.2.4/lib/devise.rb:288:in `setup'
    from /home/asavale1/rails_apps/dejalearn/releases/20150110214352/config/initializers/devise.rb:3:in `<top (required)>'
    from /home/asavale1/rails_apps/dejalearn/shared/bundle/ruby/2.1.0/gems/activesupport-4.0.2/lib/active_support/dependencies.rb:223:in `load'
    from /home/asavale1/rails_apps/dejalearn/shared/bundle/ruby/2.1.0/gems/activesupport-4.0.2/lib/active_support/dependencies.rb:223:in `block in load'
    from /home/asavale1/rails_apps/dejalearn/shared/bundle/ruby/2.1.0/gems/activesupport-4.0.2/lib/active_support/dependencies.rb:214:in `load_dependency'
    from /home/asavale1/rails_apps/dejalearn/shared/bundle/ruby/2.1.0/gems/activesupport-4.0.2/lib/active_support/dependencies.rb:223:in `load'
    from /home/asavale1/rails_apps/dejalearn/shared/bundle/ruby/2.1.0/gems/railties-4.0.2/lib/rails/engine.rb:609:in `block (2 levels) in <class:Engine>'
    from /home/asavale1/rails_apps/dejalearn/shared/bundle/ruby/2.1.0/gems/railties-4.0.2/lib/rails/engine.rb:608:in `each'
    from /home/asavale1/rails_apps/dejalearn/shared/bundle/ruby/2.1.0/gems/railties-4.0.2/lib/rails/engine.rb:608:in `block in <class:Engine>'
    from /home/asavale1/rails_apps/dejalearn/shared/bundle/ruby/2.1.0/gems/railties-4.0.2/lib/rails/initializable.rb:30:in `instance_exec'
    from /home/asavale1/rails_apps/dejalearn/shared/bundle/ruby/2.1.0/gems/railties-4.0.2/lib/rails/initializable.rb:30:in `run'
    from /home/asavale1/rails_apps/dejalearn/shared/bundle/ruby/2.1.0/gems/railties-4.0.2/lib/rails/initializable.rb:55:in `block in run_initializers'
    from /home/asavale1/.rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/tsort.rb:226:in `block in tsort_each'
    from /home/asavale1/.rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/tsort.rb:348:in `block (2 levels) in each_strongly_connected_component'
    from /home/asavale1/.rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/tsort.rb:418:in `block (2 levels) in each_strongly_connected_component_from'
    from /home/asavale1/.rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/tsort.rb:427:in `each_strongly_connected_component_from'
    from /home/asavale1/.rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/tsort.rb:417:in `block in each_strongly_connected_component_from'
    from /home/asavale1/rails_apps/dejalearn/shared/bundle/ruby/2.1.0/gems/railties-4.0.2/lib/rails/initializable.rb:44:in `each'
    from /home/asavale1/rails_apps/dejalearn/shared/bundle/ruby/2.1.0/gems/railties-4.0.2/lib/rails/initializable.rb:44:in `tsort_each_child'
    from /home/asavale1/.rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/tsort.rb:411:in `call'
    from /home/asavale1/.rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/tsort.rb:411:in `each_strongly_connected_component_from'
    from /home/asavale1/.rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/tsort.rb:347:in `block in each_strongly_connected_component'
    from /home/asavale1/.rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/tsort.rb:345:in `each'
    from /home/asavale1/.rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/tsort.rb:345:in `call'
    from /home/asavale1/.rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/tsort.rb:345:in `each_strongly_connected_component'
    from /home/asavale1/.rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/tsort.rb:224:in `tsort_each'
    from /home/asavale1/.rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/tsort.rb:205:in `tsort_each'
    from /home/asavale1/rails_apps/dejalearn/shared/bundle/ruby/2.1.0/gems/railties-4.0.2/lib/rails/initializable.rb:54:in `run_initializers'
    from /home/asavale1/rails_apps/dejalearn/shared/bundle/ruby/2.1.0/gems/railties-4.0.2/lib/rails/application.rb:215:in `initialize!'
    from /home/asavale1/rails_apps/dejalearn/shared/bundle/ruby/2.1.0/gems/railties-4.0.2/lib/rails/railtie/configurable.rb:30:in `method_missing'
    from /home/asavale1/rails_apps/dejalearn/releases/20150110214352/config/environment.rb:5:in `<top (required)>'
    from /home/asavale1/rails_apps/dejalearn/shared/bundle/ruby/2.1.0/gems/activesupport-4.0.2/lib/active_support/dependencies.rb:229:in `require'
    from /home/asavale1/rails_apps/dejalearn/shared/bundle/ruby/2.1.0/gems/activesupport-4.0.2/lib/active_support/dependencies.rb:229:in `block in require'
    from /home/asavale1/rails_apps/dejalearn/shared/bundle/ruby/2.1.0/gems/activesupport-4.0.2/lib/active_support/dependencies.rb:214:in `load_dependency'
    from /home/asavale1/rails_apps/dejalearn/shared/bundle/ruby/2.1.0/gems/activesupport-4.0.2/lib/active_support/dependencies.rb:229:in `require'
    from /home/asavale1/rails_apps/dejalearn/releases/20150110214352/config.ru:3:in `block in <main>'
    from /home/asavale1/rails_apps/dejalearn/shared/bundle/ruby/2.1.0/gems/rack-1.5.2/lib/rack/builder.rb:55:in `instance_eval'
    from /home/asavale1/rails_apps/dejalearn/shared/bundle/ruby/2.1.0/gems/rack-1.5.2/lib/rack/builder.rb:55:in `initialize'
    from /home/asavale1/rails_apps/dejalearn/releases/20150110214352/config.ru:in `new'
    from /home/asavale1/rails_apps/dejalearn/releases/20150110214352/config.ru:in `<main>'
    from /home/asavale1/rails_apps/dejalearn/shared/bundle/ruby/2.1.0/gems/rack-1.5.2/lib/rack/builder.rb:49:in `eval'
    from /home/asavale1/rails_apps/dejalearn/shared/bundle/ruby/2.1.0/gems/rack-1.5.2/lib/rack/builder.rb:49:in `new_from_string'
    from /home/asavale1/rails_apps/dejalearn/shared/bundle/ruby/2.1.0/gems/rack-1.5.2/lib/rack/builder.rb:40:in `parse_file'
    from /home/asavale1/rails_apps/dejalearn/shared/bundle/ruby/2.1.0/gems/rack-1.5.2/lib/rack/server.rb:277:in `build_app_and_options_from_config'
    from /home/asavale1/rails_apps/dejalearn/shared/bundle/ruby/2.1.0/gems/rack-1.5.2/lib/rack/server.rb:199:in `app'
    from /home/asavale1/rails_apps/dejalearn/shared/bundle/ruby/2.1.0/gems/railties-4.0.2/lib/rails/commands/server.rb:48:in `app'
    from /home/asavale1/rails_apps/dejalearn/shared/bundle/ruby/2.1.0/gems/rack-1.5.2/lib/rack/server.rb:314:in `wrapped_app'
    from /home/asavale1/rails_apps/dejalearn/shared/bundle/ruby/2.1.0/gems/railties-4.0.2/lib/rails/commands/server.rb:75:in `start'
    from /home/asavale1/rails_apps/dejalearn/shared/bundle/ruby/2.1.0/gems/railties-4.0.2/lib/rails/commands.rb:76:in `block in <top (required)>'
    from /home/asavale1/rails_apps/dejalearn/shared/bundle/ruby/2.1.0/gems/railties-4.0.2/lib/rails/commands.rb:71:in `tap'
    from /home/asavale1/rails_apps/dejalearn/shared/bundle/ruby/2.1.0/gems/railties-4.0.2/lib/rails/commands.rb:71:in `<top (required)>'
    from bin/rails:4:in `require'
    from bin/rails:4:in `<main>'

因此它似乎不喜欢我的database.yml文件。这是我的database.yml

production:
  adapter: mysql2
  database: asavale1_dejalearn
  username: ENV['DB_USER']
  password: ENV['DB_PASS']
  pool: 5
  timeout: 5000

为什么我能够运行bundle exec rails console production但是当我尝试运行我的rails服务器时,它会抱怨适配器。它们是否都使用相同的databse.yml文件连接到数据库?我的RAILS_ENV正在制作中。

由于

1 个答案:

答案 0 :(得分:2)

看起来您正在生产环境中明确启动控制台,并在(默认)开发环境中启动服务器。尝试运行bundle exec rails server -e $RAILS_ENV。如果这不起作用,请尝试bundle exec rails server -e production