我正在使用 MySQL 和 ruby 1.8.6。我想连接到 MySQL,因此我正在使用活动记录 gem。我的代码是
def initialize
@db_adapter = "mysql2"
@db_host = "localhost"
@db_database = "database_name"
@db_user = "root"
@db_password = "root123"
con = nil
end
def database_connection
con = ActiveRecord::Base.establish_connection(
:adapter => $db_adapter,
:host => $db_host,
:database => $db_database,
:user => $db_user,
:password => $db_password
)
return con
end
但是当我试图连接时,它给了我这个错误
/usr/lib/ruby/gems/1.8/gems/activerecord-2.3.8/lib/active_record/connection_adapters/abstract/connection_specification.rb:76:in `establish_connection': Please install the adapter: `gem install activerecord--adapter` (no such file to load -- active_record/connection_adapters/_adapter) (RuntimeError)
from /cmf/samnew/build/Controller/databaseConnection.rb:32:in `database_connection'
from controller.rb:23