2

尝试在我的项目上启动 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 启动并在生产中正常运行。原因可能是什么?

4

1 回答 1

4

而不是rails console RAILS_ENV=production

使用rails console production或更短的rails c production.

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

于 2013-06-25T23:30:33.423 回答