nil的未定义方法`sub':调用bundle exec db操作时的NilClass

时间:2013-08-07 18:16:20

标签: ruby-on-rails ruby macos

我收到以下错误:

undefined method `sub' for nil:NilClass
/Users/jdrm/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-3.2.13/lib/active_record/connection_adapters/abstract/connection_specification.rb:68:in `connection_url_to_hash'

当我尝试在任何rails项目上运行bundle exec db操作时,例如:

bundle exec rake db:migrate

我的操作系统是Mac OS X 10.8.4,我使用RVM安装了ruby,并且已经尝试过以下版本:

ruby-1.9.3-p448 [ x86_64 ]
ruby-2.0.0-p0 [ x86_64 ]
ruby-2.0.0-p247 [ x86_64 ]

还尝试使用rails 3.13和3.14。

我很欣赏有关此问题的任何建议。

1 个答案:

答案 0 :(得分:3)

connection_specification.rb的相关代码:

      spec = { :adapter  => adapter,
               :username => config.user,
               :password => config.password,
               :port     => config.port,
 =>            :database => config.path.sub(%r{^/},""),
               :host     => config.host }

发生错误是因为您的适配器没有数据库路径的条目。但是,如果您遵循此处引导的逻辑,则此方法将URI转换为配置对象。不是你想要的。

那为什么会这样呢?最可能的原因是没有找到正确的配置。检查您的环境中RAILS_ENV的值(如果有),以及是否存在匹配的配置。