Cannot load mysql2 gem - ruby-on-rails

I've already seen some different answers, but none of these helped me...
This is the trick: I have to fix this without touching the Gemfile. I'm currently creating my working environment so that it matches the production server, so, I cannot modify the rails' code at all.
My OS: OSX 10.11
Ruby: ruby 2.0.0p643
Rails: 4.0.0
The gem is the Gemfile as gem 'mysql2'. There are no errors when doing bundle install, but when I try to rake db:migrate --trace this is the output:
rake aborted!
There was an error while trying to load the gem 'mysql2'.
/Users/redar/.rvm/gems/ruby-2.0.0-p643/gems/bundler-1.11.2/lib/bundler/runtime.rb:80:in `rescue in block (2 levels) in require'
/Users/redar/.rvm/gems/ruby-2.0.0-p643/gems/bundler-1.11.2/lib/bundler/runtime.rb:76:in `block (2 levels) in require'
/Users/redar/.rvm/gems/ruby-2.0.0-p643/gems/bundler-1.11.2/lib/bundler/runtime.rb:72:in `each'
/Users/redar/.rvm/gems/ruby-2.0.0-p643/gems/bundler-1.11.2/lib/bundler/runtime.rb:72:in `block in require'
/Users/redar/.rvm/gems/ruby-2.0.0-p643/gems/bundler-1.11.2/lib/bundler/runtime.rb:61:in `each'
/Users/redar/.rvm/gems/ruby-2.0.0-p643/gems/bundler-1.11.2/lib/bundler/runtime.rb:61:in `require'
/Users/redar/.rvm/gems/ruby-2.0.0-p643/gems/bundler-1.11.2/lib/bundler.rb:99:in `require'
/Users/redar/redar/config/application.rb:7:in `<top (required)>'
/Users/redar/redar/Rakefile:4:in `require'
/Users/redar/redar/Rakefile:4:in `<top (required)>'
/Users/redar/.rvm/gems/ruby-2.0.0-p643/gems/rake-10.1.0/lib/rake/rake_module.rb:25:in `load'
/Users/redar/.rvm/gems/ruby-2.0.0-p643/gems/rake-10.1.0/lib/rake/rake_module.rb:25:in `load_rakefile'
/Users/redar/.rvm/gems/ruby-2.0.0-p643/gems/rake-10.1.0/lib/rake/application.rb:637:in `raw_load_rakefile'
/Users/redar/.rvm/gems/ruby-2.0.0-p643/gems/rake-10.1.0/lib/rake/application.rb:94:in `block in load_rakefile'
/Users/redar/.rvm/gems/ruby-2.0.0-p643/gems/rake-10.1.0/lib/rake/application.rb:165:in `standard_exception_handling'
/Users/redar/.rvm/gems/ruby-2.0.0-p643/gems/rake-10.1.0/lib/rake/application.rb:93:in `load_rakefile'
/Users/redar/.rvm/gems/ruby-2.0.0-p643/gems/rake-10.1.0/lib/rake/application.rb:77:in `block in run'
/Users/redar/.rvm/gems/ruby-2.0.0-p643/gems/rake-10.1.0/lib/rake/application.rb:165:in `standard_exception_handling'
/Users/redar/.rvm/gems/ruby-2.0.0-p643/gems/rake-10.1.0/lib/rake/application.rb:75:in `run'
/Users/redar/.rvm/gems/ruby-2.0.0-p643/gems/rake-10.1.0/bin/rake:33:in `<top (required)>'
/Users/redar/.rvm/gems/ruby-2.0.0-p643/bin/rake:23:in `load'
/Users/redar/.rvm/gems/ruby-2.0.0-p643/bin/rake:23:in `<main>'
/Users/redar/.rvm/gems/ruby-2.0.0-p643/bin/ruby_executable_hooks:15:in `eval'
/Users/redar/.rvm/gems/ruby-2.0.0-p643/bin/ruby_executable_hooks:15:in `<main>'
I don't know how to interpret this. Is there something wrong with the Rakefile?
Also, this is the output from the mkmf.log
EDIT: This is the content of my Rakefile, located at myapp/folder
# Add your own tasks in files placed in lib/tasks ending in .rake,
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
require File.expand_path('../config/application', __FILE__)
MyApp::Application.load_tasks

Try
bundle exec rake db:migrate
This will make sure that you are executing "rake db:migrate" with the gems listed in the Gemfile loaded and available. If you run it without "bundle exec" you may be executing only with the system gems available.

Related

rake says "cannot load such file -- spec"

I am using:
Ubuntu 12.10
Rails 3.2.12
ruby 1.9.3p194 (2012-04-20 revision 35410) [x86_64-linux]
rake rake-10.0.4
When I run rake db:create I get this error message:
rake aborted!
cannot load such file -- spec
/var/lib/gems/1.9.1/gems/bundler-1.3.5/lib/bundler/runtime.rb:72:in `require'
/var/lib/gems/1.9.1/gems/bundler-1.3.5/lib/bundler/runtime.rb:72:in `block (2 levels) in require'
/var/lib/gems/1.9.1/gems/bundler-1.3.5/lib/bundler/runtime.rb:70:in `each'
/var/lib/gems/1.9.1/gems/bundler-1.3.5/lib/bundler/runtime.rb:70:in `block in require'
/var/lib/gems/1.9.1/gems/bundler-1.3.5/lib/bundler/runtime.rb:59:in `each'
/var/lib/gems/1.9.1/gems/bundler-1.3.5/lib/bundler/runtime.rb:59:in `require'
/var/lib/gems/1.9.1/gems/bundler-1.3.5/lib/bundler.rb:132:in `require'
/home/lcastano/dev/roommateflatfinder/config/application.rb:7:in `<top (required)>'
/usr/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
/usr/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
/home/lcastano/dev/roommateflatfinder/Rakefile:5:in `<top (required)>'
/var/lib/gems/1.9.1/gems/rake-10.0.4/lib/rake/rake_module.rb:25:in `load'
/var/lib/gems/1.9.1/gems/rake-10.0.4/lib/rake/rake_module.rb:25:in `load_rakefile'
/var/lib/gems/1.9.1/gems/rake-10.0.4/lib/rake/application.rb:589:in `raw_load_rakefile'
/var/lib/gems/1.9.1/gems/rake-10.0.4/lib/rake/application.rb:89:in `block in load_rakefile'
/var/lib/gems/1.9.1/gems/rake-10.0.4/lib/rake/application.rb:160:in `standard_exception_handling'
/var/lib/gems/1.9.1/gems/rake-10.0.4/lib/rake/application.rb:88:in `load_rakefile'
/var/lib/gems/1.9.1/gems/rake-10.0.4/lib/rake/application.rb:72:in `block in run'
/var/lib/gems/1.9.1/gems/rake-10.0.4/lib/rake/application.rb:160:in `standard_exception_handling'
/var/lib/gems/1.9.1/gems/rake-10.0.4/lib/rake/application.rb:70:in `run'
/var/lib/gems/1.9.1/gems/rake-10.0.4/bin/rake:33:in `<top (required)>'
/usr/local/bin/rake:23:in `load'
/usr/local/bin/rake:23:in `<main>'
I tried uninstalling rake and re-installing it. Anyone else have the same problem?
Problem
You have an invalid statement in your Rakefile or Gemfile. You probably meant 'rspec' or 'rspec-rails' instead. Rake itself is telling you so:
cannot load such file -- spec
Solution
Remove the reference to "spec" in your Rakefile or Gemfile, or replace the problematic line with the correct name of the gem or library you're trying to use.

can't get rake spec to work

I'm following a tutorial to learn Ruby + Rails, and can't get rspec to work for me.
http://rubysource.com/rails-deep-dive-loccasions-home-page/
I am up to 'Our First Test', and when I run rake spec I get the following error:
harley-alexanders-macbook-pro:loccasions Harley$ rake spec
/Users/Harley/.rvm/rubies/ruby-1.9.3-p0/bin/ruby -S rspec ./spec/acceptance/home_page_spec.rb
/Users/Harley/.rvm/gems/ruby-1.9.3-p0#loccasions/gems/activesupport-3.2.1/lib/active_support/dependencies.rb:251:in `require': cannot load such file -- rspec/capybara (LoadError)
from /Users/Harley/.rvm/gems/ruby-1.9.3-p0#loccasions/gems/activesupport-3.2.1/lib/active_support/dependencies.rb:251:in `block in require'
from /Users/Harley/.rvm/gems/ruby-1.9.3-p0#loccasions/gems/activesupport-3.2.1/lib/active_support/dependencies.rb:236:in `load_dependency'
from /Users/Harley/.rvm/gems/ruby-1.9.3-p0#loccasions/gems/activesupport-3.2.1/lib/active_support/dependencies.rb:251:in `require'
from /Users/Harley/Sites/rails/loccasions/spec/spec_helper.rb:6:in `<top (required)>'
from /Users/Harley/Sites/rails/loccasions/spec/acceptance/home_page_spec.rb:1:in `require'
from /Users/Harley/Sites/rails/loccasions/spec/acceptance/home_page_spec.rb:1:in `<top (required)>'
from /Users/Harley/.rvm/gems/ruby-1.9.3-p0#loccasions/gems/rspec-core-2.9.0/lib/rspec/core/configuration.rb:746:in `load'
from /Users/Harley/.rvm/gems/ruby-1.9.3-p0#loccasions/gems/rspec-core-2.9.0/lib/rspec/core/configuration.rb:746:in `block in load_spec_files'
from /Users/Harley/.rvm/gems/ruby-1.9.3-p0#loccasions/gems/rspec-core-2.9.0/lib/rspec/core/configuration.rb:746:in `map'
from /Users/Harley/.rvm/gems/ruby-1.9.3-p0#loccasions/gems/rspec-core-2.9.0/lib/rspec/core/configuration.rb:746:in `load_spec_files'
from /Users/Harley/.rvm/gems/ruby-1.9.3-p0#loccasions/gems/rspec-core-2.9.0/lib/rspec/core/command_line.rb:22:in `run'
from /Users/Harley/.rvm/gems/ruby-1.9.3-p0#loccasions/gems/rspec-core-2.9.0/lib/rspec/core/runner.rb:69:in `run'
from /Users/Harley/.rvm/gems/ruby-1.9.3-p0#loccasions/gems/rspec-core-2.9.0/lib/rspec/core/runner.rb:10:in `block in autorun'
rake aborted!
/Users/Harley/.rvm/rubies/ruby-1.9.3-p0/bin/ruby -S rspec ./spec/acceptance/home_page_spec.rb failed
Tasks: TOP => spec
(See full trace by running task with --trace)
I found multiple times that the issue was outdated gems, but I've updated them all and my Gemfile to reflect this as well.
I know that 'feature' is a method of capybara- gem used for matching scenarios, etc. I'm including require('rspec/capybara') in my spec/spec_helber.rb file as well as having it in my Gemfile.
What am I doing wrong!?
Cheers,
~Harley
Try instead:
bundle exec rake spec

rake db:miagrate aborted abnormal: rake aborted! uninitialized constant Rake::DSL

Anyone could help me?
I searched the same problem, but I can't figure out a solution still.
I ran successfully with "bundle update" "bundle install" but when running "rake db:migrate" I got the following problem...
rake aborted!
uninitialized constant Rake::DSL
C:/Ruby192/lib/ruby/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/tasklib.rb:8:in `<clas
s:TaskLib>'
C:/Ruby192/lib/ruby/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/tasklib.rb:6:in `<modu
le:Rake>'
C:/Ruby192/lib/ruby/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/tasklib.rb:3:in `<top
(required)>'
C:/Ruby192/lib/ruby/gems/1.9.1/gems/rdoc-3.11/lib/rdoc/task.rb:37:in `<top (requ
ired)>'
C:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.0.9/lib/rails/tasks/documentation
.rake:2:in `<top (required)>'
C:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.0.9/lib/rails/tasks.rb:15:in `blo
ck in <top (required)>'
C:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.0.9/lib/rails/tasks.rb:6:in `each
'
C:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.0.9/lib/rails/tasks.rb:6:in `<top
(required)>'
C:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.0.9/lib/rails/application.rb:215:
in `initialize_tasks'
C:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.0.9/lib/rails/application.rb:139:
in `load_tasks'
C:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.0.9/lib/rails/application.rb:77:i
n `method_missing'
C:/F/desktop/Projects/recle/recle/rails/eway/Rakefile:7:in `<top (required)>'
C:/Ruby192/lib/ruby/1.9.1/rake.rb:2373:in `load'
C:/Ruby192/lib/ruby/1.9.1/rake.rb:2373:in `raw_load_rakefile'
C:/Ruby192/lib/ruby/1.9.1/rake.rb:2007:in `block in load_rakefile'
C:/Ruby192/lib/ruby/1.9.1/rake.rb:2058:in `standard_exception_handling'
C:/Ruby192/lib/ruby/1.9.1/rake.rb:2006:in `load_rakefile'
C:/Ruby192/lib/ruby/1.9.1/rake.rb:1991:in `run'
C:/Ruby192/bin/rake:31:in `<main>'
Put this in your Rakefile above require 'rake':
require 'rake/dsl_definition'
OR if the above solution does not work,
write this in your gemfile for rake
gem "rake", "0.8.7"
and go to command prompt and write.
gem uninstall rake
This will uninstall the existing rake gem.
Then type bundle update in your project folder which will install rake 9.8.7 again.
And enjoy rails :).

Deploying to Heroku

Following this tutorial, I applied the steps for deploying to Heroku under 2.3.5 Deploying the demo app.
When I run the command: > heroku rake db:migrate, I get the following:
$ heroku rake db:migrate
(in /app)
rake aborted!
uninitialized constant Rake::DSL
/usr/ruby1.9.2/lib/ruby/1.9.1/rake.rb:2482:in `const_missing'
/app/.bundle/gems/ruby/1.9.1/gems/rake-0.9.2/lib/rake/tasklib.rb:8:in `<class:Ta
skLib>'
/app/.bundle/gems/ruby/1.9.1/gems/rake-0.9.2/lib/rake/tasklib.rb:6:in `<module:R
ake>'
/app/.bundle/gems/ruby/1.9.1/gems/rake-0.9.2/lib/rake/tasklib.rb:3:in `<top (req
uired)>'
/app/.bundle/gems/ruby/1.9.1/gems/rdoc-3.8/lib/rdoc/task.rb:37:in `require'
/app/.bundle/gems/ruby/1.9.1/gems/rdoc-3.8/lib/rdoc/task.rb:37:in `<top (require
d)>'
/app/.bundle/gems/ruby/1.9.1/gems/railties-3.0.9/lib/rails/tasks/documentation.r
ake:2:in `require'
/app/.bundle/gems/ruby/1.9.1/gems/railties-3.0.9/lib/rails/tasks/documentation.r
ake:2:in `<top (required)>'
/app/.bundle/gems/ruby/1.9.1/gems/railties-3.0.9/lib/rails/tasks.rb:15:in `load'
/app/.bundle/gems/ruby/1.9.1/gems/railties-3.0.9/lib/rails/tasks.rb:15:in `block
in <top (required)>'
/app/.bundle/gems/ruby/1.9.1/gems/railties-3.0.9/lib/rails/tasks.rb:6:in `each'
/app/.bundle/gems/ruby/1.9.1/gems/railties-3.0.9/lib/rails/tasks.rb:6:in `<top (
required)>'
/app/.bundle/gems/ruby/1.9.1/gems/railties-3.0.9/lib/rails/application.rb:215:in
`require'
/app/.bundle/gems/ruby/1.9.1/gems/railties-3.0.9/lib/rails/application.rb:215:in
`initialize_tasks'
/app/.bundle/gems/ruby/1.9.1/gems/railties-3.0.9/lib/rails/application.rb:139:in
`load_tasks'
/app/.bundle/gems/ruby/1.9.1/gems/railties-3.0.9/lib/rails/application.rb:77:in
`method_missing'
/app/Rakefile:7:in `<top (required)>'
/usr/ruby1.9.2/lib/ruby/1.9.1/rake.rb:2373:in `load'
/usr/ruby1.9.2/lib/ruby/1.9.1/rake.rb:2373:in `raw_load_rakefile'
/usr/ruby1.9.2/lib/ruby/1.9.1/rake.rb:2007:in `block in load_rakefile'
/usr/ruby1.9.2/lib/ruby/1.9.1/rake.rb:2058:in `standard_exception_handling'
/usr/ruby1.9.2/lib/ruby/1.9.1/rake.rb:2006:in `load_rakefile'
/usr/ruby1.9.2/lib/ruby/1.9.1/rake.rb:1991:in `run'
/usr/ruby1.9.2/bin/rake:31:in `<main>'
Why is that? And, how can I solve this issue?
Thanks.
I have a blog post about it here:
http://codeglot.com/posts/13-you_have_already_activated_rake_0_9_2
You have two options. Keep the latest gem and do this:
# Add your own tasks in files placed in lib/tasks ending in .rake,
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
require File.expand_path('../config/application', __FILE__)
require 'rake/dsl_definition'
require 'rake'
Or you need to specify the older version of rake:
gem list
Then see which version of rake you have.
gem uninstall rake -v=0.9.1
Then in your bundler specify the older version:
gem 'rake', '0.8.7'
This link may help: fix unitialized constant rake heroku
Form that post:
Put this in your Rakefile above require 'rake':
require 'rake/dsl_definition'

Not able to start Rails server

I am working on Ubuntu 10.04 LTS, Lucid Lynx, have installed Ruby on Rails 3 on it. I am not able to start Rails server. I am getting the following error.
mah#mah-laptop:~/Desktop/projects/ver$ rails s
/home/mah/.rvm/gems/ruby-1.9.2-p0/gems/railties-3.0.8/lib/rails/commands.rb:29:in `block in <top (required)>': undefined method `root' for nil:NilClass (NoMethodError)
from /home/mah/.rvm/gems/ruby-1.9.2-p0/gems/railties-3.0.8/lib/rails/commands.rb:27:in `tap'
from /home/mah/.rvm/gems/ruby-1.9.2-p0/gems/railties-3.0.8/lib/rails/commands.rb:27:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'
I am using Rails 3.0.8 and rake version 0.8.7
I tried bundle exec but got same error.
Thanks for any help in advance
UPDATE
Here is what I get after bundle exec rake db:migrate --trace
mah#mah-laptop:~/Desktop/projects/ver$ bundle exec rake db:migrate --trace
rake aborted!
uninitialized constant Ver
/home/mah/.rvm/gems/ruby-1.9.2-p0/gems/aws-s3-0.6.2/lib/aws/s3/extensions.rb:206:in `const_missing_from_s3_library'
/home/mah/Desktop/projects/ver/Rakefile:7:in `<top (required)>'
/home/mah/.rvm/gems/ruby-1.9.2-p0/gems/rake-0.9.2/lib/rake/rake_module.rb:25:in `load'
/home/mah/.rvm/gems/ruby-1.9.2-p0/gems/rake-0.9.2/lib/rake/rake_module.rb:25:in `load_rakefile'
/home/mah/.rvm/gems/ruby-1.9.2-p0/gems/rake-0.9.2/lib/rake/application.rb:495:in `raw_load_rakefile'
/home/mah/.rvm/gems/ruby-1.9.2-p0/gems/rake-0.9.2/lib/rake/application.rb:78:in `block in load_rakefile'
/home/mah/.rvm/gems/ruby-1.9.2-p0/gems/rake-0.9.2/lib/rake/application.rb:129:in `standard_exception_handling'
/home/mah/.rvm/gems/ruby-1.9.2-p0/gems/rake-0.9.2/lib/rake/application.rb:77:in `load_rakefile'
/home/mah/.rvm/gems/ruby-1.9.2-p0/gems/rake-0.9.2/lib/rake/application.rb:61:in `block in run'
/home/mah/.rvm/gems/ruby-1.9.2-p0/gems/rake-0.9.2/lib/rake/application.rb:129:in `standard_exception_handling'
/home/mah/.rvm/gems/ruby-1.9.2-p0/gems/rake-0.9.2/lib/rake/application.rb:59:in `run'
/home/mah/.rvm/gems/ruby-1.9.2-p0/gems/rake-0.9.2/bin/rake:32:in `<top (required)>'
/home/mah/.rvm/gems/ruby-1.9.2-p0/bin/rake:19:in `load'
/home/mah/.rvm/gems/ruby-1.9.2-p0/bin/rake:19:in `<main>'
This error means that Rails.application isn't initialized. I didn't actually know that, I
cheated.
So that then begs the question: how did you set up this application?
Perhaps this application doesn't contain a config/application.rb file that defines a class that inherits from Rails::Application and therefore is causing this problem. In my application here, I've got this one you could use as an example.

Resources