【发布时间】:2015-11-08 17:02:47
【问题描述】:
我为 mysql2 和 Active Record 安装了 gem。当我运行我的代码时,我得到一个错误:
/usr/local/opt/rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/activerecord-4.2.4/lib/active_record/connection_adapters/connection_specification.rb:177:in` `rescue in spec': Specified 'my sql2' for database adapter, but the gem is not loaded. Add `gem 'mysql2'` to your Gemfile (and ensure its version is at the minimum required by ActiveRecord). (Gem::LoadError)
from /usr/local/opt/rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/activerecord-4.2.4/lib/active_record/connection_adapters/connection_specification.rb:174:in `spec'
from `/usr/local/opt/rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/activerecord-4.2.4/lib/active_record/connection_handling.rb:50:in `establish_connection'
这是我的代码:
require 'mysql2'
require 'active_record'
client = Mysql2::Client.new(:host => "localhost", :username => "root")
client.query("show databases").each do |db|
p db
end
ActiveRecord::Base.establish_connection(
adapter: 'mysql2',
databases: 'store_manager'
)
错误是说我需要将我的 sql2 添加到我的 gemfile。我在哪里可以找到它,有什么需要补充的吗?
【问题讨论】:
标签: ruby activerecord gem