无法在生产中启动rails控制台

时间:2013-01-12 19:33:19

标签: ruby-on-rails sqlite console

尝试在项目中启动rails控制台时出现此错误:

/home/username/.rvm/gems/ruby-1.9.3-p362/gems/activerecord-3.2.8/lib/active_record/connection_adapters/abstract/connection_specification.rb:47:in `resolve_hash_connection': database configuration does not specify adapter (ActiveRecord::AdapterNotSpecified)
from /home/username/.rvm/gems/ruby-1.9.3-p362/gems/activerecord-3.2.8/lib/active_record/connection_adapters/abstract/connection_specification.rb:41:in `resolve_string_connection'
from /home/username/.rvm/gems/ruby-1.9.3-p362/gems/activerecord-3.2.8/lib/active_record/connection_adapters/abstract/connection_specification.rb:25:in `spec'
from /home/username/.rvm/gems/ruby-1.9.3-p362/gems/activerecord-3.2.8/lib/active_record/connection_adapters/abstract/connection_specification.rb:129:in `establish_connection'
from /home/username/.rvm/gems/ruby-1.9.3-p362/gems/activerecord-3.2.8/lib/active_record/railtie.rb:82:in `block (2 levels) in <class:Railtie>'
from /home/username/.rvm/gems/ruby-1.9.3-p362/gems/activesupport-3.2.8/lib/active_support/lazy_load_hooks.rb:36:in `instance_eval'
from /home/username/.rvm/gems/ruby-1.9.3-p362/gems/activesupport-3.2.8/lib/active_support/lazy_load_hooks.rb:36:in `execute_hook'
from /home/username/.rvm/gems/ruby-1.9.3-p362/gems/activesupport-3.2.8/lib/active_support/lazy_load_hooks.rb:43:in `block in run_load_hooks'
from /home/username/.rvm/gems/ruby-1.9.3-p362/gems/activesupport-3.2.8/lib/active_support/lazy_load_hooks.rb:42:in `each'
from /home/username/.rvm/gems/ruby-1.9.3-p362/gems/activesupport-3.2.8/lib/active_support/lazy_load_hooks.rb:42:in `run_load_hooks'
from /home/username/.rvm/gems/ruby-1.9.3-p362/gems/activerecord-3.2.8/lib/active_record/base.rb:721:in `<top (required)>'
from /home/username/.rvm/gems/ruby-1.9.3-p362/gems/activerecord-3.2.8/lib/active_record/railtie.rb:41:in `block in <class:Railtie>'
from /home/username/.rvm/gems/ruby-1.9.3-p362/gems/railties-3.2.8/lib/rails/railtie.rb:179:in `call'
from /home/username/.rvm/gems/ruby-1.9.3-p362/gems/railties-3.2.8/lib/rails/railtie.rb:179:in `block in load_console'
from /home/username/.rvm/gems/ruby-1.9.3-p362/gems/railties-3.2.8/lib/rails/railtie.rb:179:in `each'
from /home/username/.rvm/gems/ruby-1.9.3-p362/gems/railties-3.2.8/lib/rails/railtie.rb:179:in `load_console'
from /home/username/.rvm/gems/ruby-1.9.3-p362/gems/railties-3.2.8/lib/rails/engine.rb:429:in `block in load_console'
from /home/username/.rvm/gems/ruby-1.9.3-p362/gems/railties-3.2.8/lib/rails/application/railties.rb:8:in `each'
from /home/username/.rvm/gems/ruby-1.9.3-p362/gems/railties-3.2.8/lib/rails/application/railties.rb:8:in `all'
from /home/username/.rvm/gems/ruby-1.9.3-p362/gems/railties-3.2.8/lib/rails/engine.rb:429:in `load_console'
from /home/username/.rvm/gems/ruby-1.9.3-p362/gems/railties-3.2.8/lib/rails/application.rb:153:in `load_console'
from /home/username/.rvm/gems/ruby-1.9.3-p362/gems/railties-3.2.8/lib/rails/commands/console.rb:27:in `start'
from /home/username/.rvm/gems/ruby-1.9.3-p362/gems/railties-3.2.8/lib/rails/commands/console.rb:8:in `start'
from /home/username/.rvm/gems/ruby-1.9.3-p362/gems/railties-3.2.8/lib/rails/commands.rb:41:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'

这是我的database.yml文件(未经默认修改):

# SQLite version 3.x
#   gem install sqlite3
#
#   Ensure the SQLite 3 gem is defined in your Gemfile
#   gem 'sqlite3'
development:
  adapter: sqlite3
  database: db/development.sqlite3
  pool: 5
  timeout: 5000

# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
  adapter: sqlite3
  database: db/test.sqlite3
  pool: 5
  timeout: 5000

production:
  adapter: sqlite3
  database: db/production.sqlite3
  pool: 5
  timeout: 5000

我不相信这是一个系统特定的问题,因为它发生在我的开发环境(Fedora 17笔记本电脑)和生产环境(Debian 6 VPS)上。在VPS上,nginx + unicorn在生产中启动和服务没有问题。原因可能是什么?

1 个答案:

答案 0 :(得分:4)

而不是rails console RAILS_ENV=production

使用rails console production或缩短rails c production

调用rails控制台后的值将被视为环境,因此它认为“RAILS_ENV = production”是它应该使用的环境的名称,而不是“生产”。