0

Rails 新手,我想使用rails 控制台沙箱测试一些关联。我创建了一个非常基本的应用程序,并且rails 控制台工作得很好。

我安装了activesupport gem。

当我运行$ActiveRecord::Base.configurations[Rails.env]['adapter']命令时,它报告数据库是 sqlite3 (这是正确的。)

但是当我尝试使用控制台的“沙盒”版本时,我收到以下错误:

/Users/user/.rvm/gems/ruby-1.9.3-p194/gems/activerecord-3.2.3/lib/active_record/connection_adapters/abstract/connection_specification.rb:45:in `resolve_hash_connection': database configuration does not specify adapter (ActiveRecord::AdapterNotSpecified)
from /Users/user/.rvm/gems/ruby-1.9.3-p194/gems/activerecord-3.2.3/lib/active_record/connection_adapters/abstract/connection_specification.rb:39:in `resolve_string_connection'
from /Users/user/.rvm/gems/ruby-1.9.3-p194/gems/activerecord-3.2.3/lib/active_record/connection_adapters/abstract/connection_specification.rb:23:in `spec'
from /Users/user/.rvm/gems/ruby-1.9.3-p194/gems/activerecord-3.2.3/lib/active_record/connection_adapters/abstract/connection_specification.rb:127:in `establish_connection'
from /Users/user/.rvm/gems/ruby-1.9.3-p194/gems/activerecord-3.2.3/lib/active_record/railtie.rb:76:in `block (2 levels) in <class:Railtie>'
from /Users/user/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.2.3/lib/active_support/lazy_load_hooks.rb:36:in `instance_eval'
from /Users/user/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.2.3/lib/active_support/lazy_load_hooks.rb:36:in `execute_hook'
from /Users/user/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.2.3/lib/active_support/lazy_load_hooks.rb:43:in `block in run_load_hooks'
from /Users/user/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.2.3/lib/active_support/lazy_load_hooks.rb:42:in `each'
from /Users/user/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.2.3/lib/active_support/lazy_load_hooks.rb:42:in `run_load_hooks'
from /Users/user/.rvm/gems/ruby-1.9.3-p194/gems/activerecord-3.2.3/lib/active_record/base.rb:721:in `<top (required)>'
from /Users/user/.rvm/gems/ruby-1.9.3-p194/gems/activerecord-3.2.3/lib/active_record/railtie.rb:41:in `block in <class:Railtie>'
from /Users/user/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.3/lib/rails/railtie.rb:179:in `call'
from /Users/user/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.3/lib/rails/railtie.rb:179:in `block in load_console'
from /Users/user/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.3/lib/rails/railtie.rb:179:in `each'
from /Users/user/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.3/lib/rails/railtie.rb:179:in `load_console'
from /Users/user/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.3/lib/rails/engine.rb:429:in `block in load_console'
from /Users/user/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.3/lib/rails/application/railties.rb:8:in `each'
from /Users/user/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.3/lib/rails/application/railties.rb:8:in `all'
from /Users/user/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.3/lib/rails/engine.rb:429:in `load_console'
from /Users/user/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.3/lib/rails/application.rb:153:in `load_console'
from /Users/user/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.3/lib/rails/commands/console.rb:27:in `start'
from /Users/user/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.3/lib/rails/commands/console.rb:8:in `start'
from /Users/user/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.3/lib/rails/commands.rb:41:in `<top (required)>'

我不太确定这个错误告诉我什么,因为我正确设置了 database.yml 文件并使用标准控制台将数据写入数据库。我也不知道如何解决这个问题。

4

1 回答 1

0

您应该将沙箱作为参数传递

rails c --sandbox

否则,rails 认为沙盒是您要在其中运行控制台的环境。

于 2012-05-25T19:18:05.810 回答