Ruby on Rails and Rake problems: uninitialized constant Rake::DSL

ID : 20251

viewed : 5

Tags : ruby-on-railsrakeruby-on-rails

Top 5 Answer for Ruby on Rails and Rake problems: uninitialized constant Rake::DSL

vote vote

92

A tweet from DHH earlier. Rake .9.0 breaks Rails and several other things, you need to:

gem "rake", "0.8.7" 

in your Gemfile.

vote vote

80

I made some research just after my previous answer (sorry, I must do before it).

All problems are solved with Rake gem 0.9.2.. I followed these steps:

  • I installed gem install rake -v=0.9.2 (I had the 0.9.1 gem)
  • removed the 0.9.1 with gem uninstall rake -v=0.9.1
  • updated with bundle update
  • then the db:migrate showed a warning, WARNING: Global access to Rake DSL methods is deprecated. Please....

    It was solved by adding the following to the Rake file.

    module ::YourApplicationName     class Application     include Rake::DSL   end end 
  • I ommited the module ::RakeFileUtils extend Rake::FileUtilsExtend option sugested by @databyte.

It means that the Rake gem 0.9.2 works fine!

vote vote

78

Going through Chapter 2 of Railstutorial (demo_app) and ran into this problem. I tried all of the other answers listed here, but couldn't get it to work until I did this:

Put this in your Rakefile above require 'rake':

require 'rake/dsl_definition' 

via How to fix the uninitialized constant Rake::DSL problem on Heroku?

I also recommitted and pushed all files to Github and Heroku.

vote vote

66

All I needed to do was use:

gem install rake 

I had version 0.9.2 already, just needed installing.

vote vote

54

Reinstall the rake gem and it should work fine:

gem uninstall rake -v=0.9.2  gem install rake -v=0.9.2 

If not, specify version '0.8.7' in your Gemfile.

Top 3 video Explaining Ruby on Rails and Rake problems: uninitialized constant Rake::DSL

Related QUESTION?