数据库未配置。可用:[](ActiveRecord :: AdapterNotSpecified)

时间:2015-09-18 16:29:52

标签: mysql ruby-on-rails

尝试配置多个数据库以不同的方式将日志放在不同的数据库中

ruby/gems/2.2.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/connection_specification.rb:248:in `resolve_symbol_connection': 'log_database_development' database is not configured. Available: [] (ActiveRecord::AdapterNotSpecified)

但是当我试图运行时

  

rake db:migrate RAILS_ENV = development

我正在异常

class AccessLog < ActiveRecord::Base
  establish_connection "log_database_#{Rails.env}"
end

我试图访问此数据库的模型是

UISplitViewController

现在我的模型或连接没有出错,能帮帮我吗?

1 个答案:

答案 0 :(得分:0)

将配置部分的参数提供给establish_connection时,您需要将其作为符号提供:

establish_connection :"log_database_#{Rails.env}"

...或

establish_connection "log_database_#{Rails.env}".to_sym