简体   繁体   中英

error while trying to load the gem 'mysql2' in Ruby 1.9.3, Rails 3.2.7, mstwjs Noel Rappin tutorial app

I'm trying to get started working through Noel Rappin's very promising " Master Space and Time with JavaScript. " One hurdle stems from the fact that the code was last updated in September, 2012, and the ecosystem has moved on. I believe that my problem mostly stems from the mysql database, installing it with homebrew (I believe the latest version by default) and the mysql2 gem version Mr. Rappin used back in aught 12, 0.3.11.

I've updated the Gemfile to reflect the gem versions in the mstwjs Gemfile.lock file:

source 'http://rubygems.org'

gem 'rails',   '3.2.7'
gem 'devise',  '2.1.2'

# Bundle edge Rails instead:
#gem 'rails',     :git => 'git://github.com/rails/rails.git'

gem 'mysql2',  '0.3.11'

# Asset template engines
group :assets do
  gem 'sass-rails',   '3.2.5'
  gem 'coffee-rails', '3.2.2'
  gem 'uglifier',     '1.2.6'
end

gem 'jquery-rails',       '2.0.2'
gem 'rails-backbone',     '0.7.2'
#gem 'sprockets_spacely'

# Use unicorn as the web server
# gem 'unicorn'

# Deploy with Capistrano
# gem 'capistrano'

# To use debugger
# gem 'ruby-debug19', :require => 'ruby-debug'

group :development do
  gem 'powder',           '0.1.8'
  gem 'awesome_print',    '1.0.2'
  gem 'annotate',         '2.5.0'
end

group :test, :development do
  #gem 'guard-rails-assets'
  #gem 'guard-jasmine-headless-webkit'
  gem 'jasmine-headless-webkit', '0.8.4'
  gem 'jasmine',                 '1.2.0'
  gem 'jasminerice',             '0.0.9'
  gem 'rspec-rails',             '2.11.0'
end

Then

$ rbenv local use 1.9.3
$ brew install mysql2
$ gem install mysql2 -v ‘0.3.11’
$ bundle install

So far so good! When I try to run the mstwjs setup generator with:

$ rake mstwjs:setup --trace

I run into the following error:

rake aborted!
There was an error while trying to load the gem 'mysql2'.
/Users/benjaminunger/.rbenv/versions/1.9.3-p551/lib/ruby/gems/1.9.1/gems/bundler-1.11.2/lib/bundler/runtime.rb:81:in `rescue in block (2 levels) in require'
/Users/benjaminunger/.rbenv/versions/1.9.3-p551/lib/ruby/gems/1.9.1/gems/bundler-1.11.2/lib/bundler/runtime.rb:76:in `block (2 levels) in require'
/Users/benjaminunger/.rbenv/versions/1.9.3-p551/lib/ruby/gems/1.9.1/gems/bundler-1.11.2/lib/bundler/runtime.rb:72:in `each'
/Users/benjaminunger/.rbenv/versions/1.9.3-p551/lib/ruby/gems/1.9.1/gems/bundler-1.11.2/lib/bundler/runtime.rb:72:in `block in require'
/Users/benjaminunger/.rbenv/versions/1.9.3-p551/lib/ruby/gems/1.9.1/gems/bundler-1.11.2/lib/bundler/runtime.rb:61:in `each'
/Users/benjaminunger/.rbenv/versions/1.9.3-p551/lib/ruby/gems/1.9.1/gems/bundler-1.11.2/lib/bundler/runtime.rb:61:in `require'
/Users/benjaminunger/.rbenv/versions/1.9.3-p551/lib/ruby/gems/1.9.1/gems/bundler-1.11.2/lib/bundler.rb:99:in `require'
/Users/benjaminunger/programming/rails/mstwjs/config/application.rb:7:in `<top (required)>'
/Users/benjaminunger/.rbenv/versions/1.9.3-p551/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
/Users/benjaminunger/.rbenv/versions/1.9.3-p551/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
/Users/benjaminunger/programming/rails/mstwjs/Rakefile:5:in `<top (required)>'
/Users/benjaminunger/.rbenv/versions/1.9.3-p551/lib/ruby/1.9.1/rake/rake_module.rb:25:in `load'
/Users/benjaminunger/.rbenv/versions/1.9.3-p551/lib/ruby/1.9.1/rake/rake_module.rb:25:in `load_rakefile'
/Users/benjaminunger/.rbenv/versions/1.9.3-p551/lib/ruby/1.9.1/rake/application.rb:501:in `raw_load_rakefile'
/Users/benjaminunger/.rbenv/versions/1.9.3-p551/lib/ruby/1.9.1/rake/application.rb:82:in `block in load_rakefile'
/Users/benjaminunger/.rbenv/versions/1.9.3-p551/lib/ruby/1.9.1/rake/application.rb:133:in `standard_exception_handling'
/Users/benjaminunger/.rbenv/versions/1.9.3-p551/lib/ruby/1.9.1/rake/application.rb:81:in `load_rakefile'
/Users/benjaminunger/.rbenv/versions/1.9.3-p551/lib/ruby/1.9.1/rake/application.rb:65:in `block in run'
/Users/benjaminunger/.rbenv/versions/1.9.3-p551/lib/ruby/1.9.1/rake/application.rb:133:in `standard_exception_handling'
/Users/benjaminunger/.rbenv/versions/1.9.3-p551/lib/ruby/1.9.1/rake/application.rb:63:in `run'
/Users/benjaminunger/.rbenv/versions/1.9.3-p551/bin/rake:32:in `<main>'

Anyone have any ideas what I'm doing wrong? Would be super grateful for your insights.

I managed to get the repo working by making the following changes:

# Gemfile
gem 'mysql2', '~> 0.3.20'

bundle update mysql2

# Create config/initializers/abstract_mysql2_adapter.rb
class ActiveRecord::ConnectionAdapters::Mysql2Adapter
    NATIVE_DATABASE_TYPES[:primary_key] = "int(11) auto_increment PRIMARY KEY"
end

bundle exec rake mstwjs:setup --trace

Got it working.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM