问题描述:

I've started writing a Ruby script which will be called as part of rake db:seed, and it looks like this:

require 'rubygems'

require 'mysql'

When I try to run it, I get:

rake aborted!

cannot load such file -- mysql

However, I can use require 'mysql' from within irb, and I can do this:

$ gem query --local | grep mysql

mysql (2.9.0)

Does anybody know what's up?

e: for fun, I put puts Gem.path at the top of my script, and got:

/usr/local/rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1

/home/vagrant/.gem/ruby/1.9.1

Compare that to Gem env:

 - /usr/local/rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1

- /home/vagrant/.gem/ruby/1.9.1

No dice.

网友答案:

Answered. I had to add the following lines in my Gemfile:

gem 'mysql2'

After that, I ran bundle install and it worked.

相关阅读:
Top