Michael
Michael

Reputation: 644

Rake gem problem

I've got this ruby on rails project and I want to do db:migrate. But the only rake option I got is "Reload rake tasks" so when I hit that, it gives me this error.

[rake --tasks] rake aborted!
uninitialized constant Rake::DSL
/usr/lib/ruby/1.8/rake.rb:2503:in `const_missing'
/var/lib/gems/1.8/gems/rake-0.9.2/lib/rake/tasklib.rb:8
/var/lib/gems/1.8/gems/rdoc-3.9.1/lib/rdoc/task.rb:37:in `require'
/var/lib/gems/1.8/gems/rdoc-3.9.1/lib/rdoc/task.rb:37
/var/lib/gems/1.8/gems/railties-3.0.9/lib/rails/tasks/documentation.rake:2:in `require'
/var/lib/gems/1.8/gems/railties-3.0.9/lib/rails/tasks/documentation.rake:2
/var/lib/gems/1.8/gems/railties-3.0.9/lib/rails/tasks.rb:15:in `load'
/var/lib/gems/1.8/gems/railties-3.0.9/lib/rails/tasks.rb:15
/var/lib/gems/1.8/gems/railties-3.0.9/lib/rails/tasks.rb:6:in `each'
/var/lib/gems/1.8/gems/railties-3.0.9/lib/rails/tasks.rb:6
/var/lib/gems/1.8/gems/railties-3.0.9/lib/rails/application.rb:215:in `require'
/var/lib/gems/1.8/gems/railties-3.0.9/lib/rails/application.rb:215:in `initialize_tasks'
/var/lib/gems/1.8/gems/railties-3.0.9/lib/rails/application.rb:139:in `load_tasks'
/var/lib/gems/1.8/gems/railties-3.0.9/lib/rails/application.rb:77:in `send'
/var/lib/gems/1.8/gems/railties-3.0.9/lib/rails/application.rb:77:in `method_missing'
/home/laptop/RubymineProjects/auth/Rakefile:7
/usr/lib/ruby/1.8/rake.rb:2383:in `load'
/usr/lib/ruby/1.8/rake.rb:2383:in `raw_load_rakefile'
/usr/lib/ruby/1.8/rake.rb:2017:in `load_rakefile'
/usr/lib/ruby/1.8/rake.rb:2068:in `standard_exception_handling'
/usr/lib/ruby/1.8/rake.rb:2016:in `load_rakefile'
/usr/lib/ruby/1.8/rake.rb:2000:in `run'
/usr/lib/ruby/1.8/rake.rb:2068:in `standard_exception_handling'
/usr/lib/ruby/1.8/rake.rb:1998:in `run'
/usr/bin/rake:28

Thanks, Michael.

Upvotes: 0

Views: 1168

Answers (2)

Tilo
Tilo

Reputation: 33732

You should specifically add Rake version >= 0.9.1 in your Gemfile! There was a bug with some Rails 3 versions where you would see strange errors like this when you use an older Rake version.

In your Gemfile:

gem 'rake' , '>= 0.9.2'

I'd also recommend you create a new gemset specifically for your application, e.g.

rvm gemset create yourproject
rvm gemset use yourproject

or:

rvm gemset use yourproject --default

for the new gemset, you might have to add "gem install rake" manually, then run "bundle install"

Using a separate gemset in addition to using your Gemfile is the best way to keep your gem versions in your project stable, and decoupled from other projects.

Upvotes: 1

ankit
ankit

Reputation: 3358

This is a common problem. Just follow these steps:

gem install rake -v=0.9.2 (If you have the 0.9.1 gem)

gem uninstall rake -v=0.9.1 (If you have the 0.9.1 gem)

Looking at your logs, I see you have rake-0.9.2 so I think you can skip the 2 steps above.

bundle update

Then, running db:migrate will give you an error like this: WARNING: Global access to Rake DSL methods is deprecated

To solve, this you just have to add these two lines to the top of your Rakefile

require 'rake/dsl_definition'

include Rake::DSL

It should work perfectly fine after that!

Upvotes: 3

Related Questions