86

I am working through the Ruby on Rails 3 tutorial book and typed the following on the command line:

rake db:migrate

which produced the following warning.

WARNING: Global access to Rake DSL methods is deprecated.  Please Include
    ...  Rake::DSL into classes and modules which use the Rake DSL methods.

WARNING: DSL method DemoApp::Application#task called at /Users/imac/.rvm/gems/ruby-1.9.2-p180@rails3tutorial/gems/railties-3.0.7/lib/rails/application.rb:215:in `initialize_tasks'

I am not sure what to do about it or how to work with it. I don't know any other command for Rake.

How can I fix this problem?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
chell
  • 7,646
  • 16
  • 74
  • 140

5 Answers5

111

Adding include Rake::DSL to the Rakefile before the applications load_tasks were called also worked for me.

So in the above user's case before the DemoApp::Application.load_tasks in the Rakefile.

Patelify
  • 1,800
  • 2
  • 13
  • 14
  • Thanks. Fixed my "WARNING: Global access to Rake DSL methods is deprecated." problem. – Slobodan Kovacevic Jun 12 '11 at 11:41
  • Is this the proper way to fix this issue? – Marc Jun 15 '11 at 08:54
  • 2
    @Marc, currently this is the only fix I know off without upgrading to rails 3.0.8 or higher. This issue is resolved in that release: https://github.com/rails/rails/commit/83f257fc4862642af29056cb5b7dfef6e1303754. If you find a better fix please let me know. Also, according to the warning I would think that it is the proper fix. – Patelify Jun 16 '11 at 09:14
  • 1
    This is the solution I went with. I'd prefer to simply add the line than to play games with which version of Rake works with what. – jaydel Jun 20 '11 at 12:36
  • 2
    This worked for me with 1.9.2 and Rails 3.0.7 with Rake 0.9.2 – Steven Chanin Jul 19 '11 at 16:46
  • This works for me as well with Rails 3.0 ,ruby 1.9.2 Rake 0.9.2. – pierrotlefou Sep 03 '11 at 09:03
  • This worked for me for server load and console load, but I still get the warnings when running rake db:migrate etc.. any ideas? – Joelio Nov 13 '12 at 15:59
  • NB: This caused a subtle issue for me, where the following modules were being mixed into ActiveRecord::Base: Rake::DSL, Rake::FileUtilsExt, FileUtils, FileUtils::StreamUtils_. One of them (I think FileUtils) was overwriting a field called #link on some of the models with a private method used for creating symlinks. – Eric Walker Oct 13 '16 at 22:39
64

I found this in Stack Overflow question Ruby on Rails and Rake problems: uninitialized constant Rake::DSL. It refers to a @DHH tweet.

Put the following in your Gemfile

gem "rake", "0.8.7"

You may see something like

rake aborted!
You have already activated Rake 0.9.1 ...

I still had a copy of Rake 0.9.1 in my directory so I deleted it.

You can "delete" Rake 0.9.1 by running the following command:

gem uninstall rake -v=0.9.1

If you have multiple versions of the gem installed, you'll be prompted to pick a version.

After 0.9.1 was cleaned out, I ran

bundle update rake

and was finally able to create my database files. I was using rake db:create, but it should work for rake db:migrate as well.

I hope it helps.

Community
  • 1
  • 1
Brian Bruijn
  • 736
  • 6
  • 2
  • 1
    I agree with Antonio - when I said to remove rake 0.9.1 I meant through using `gem uninstall rake -v=0.9.1`. My mistake for not making it clear. Thanks for the clarification Antonio! Cheers, Brian – Brian Bruijn Jun 01 '11 at 17:46
  • 5
    That did not work for me. I had to actually remove rake 0.9.1 > gem uninstall rake -v=0.9.1 and then > bundle update Thanks Antonio –  Jun 01 '11 at 12:20
  • 13
    I don’t think it’s good to deliberately use old libraries, when newer one can be made to work, seeing comment below. – Smar Jun 11 '11 at 19:52
  • 2
    The more simple solution is the one suggested by NPatel below. Just add one line to Rakefile. – Slobodan Kovacevic Jun 12 '11 at 11:43
  • I didn't have any luck with this resolution. It still came up with the same error after uninstalling rake 0.9.1 or 0.9.2 then running bundle update. – Marc Jun 15 '11 at 08:55
5

I was having the same problem on Windows with the installer. Ruby 1.9.2 and Rails 3.0.9. Here is what I did:

bundle update rake
bundle show rake

After doing that I was running rake 0.9.2.

Then I updated the Rakefile in application root folder as follows:

require File.expand_path('../config/application', __FILE__)
require 'rake'
# If you named your application something other than SampleApp, change that below
module ::SampleApp
    class Application
        include Rake::DSL
    end
end

module ::RakeFileUtils
    extend Rake::FileUtilsExt
end

SampleApp::Application.load_tasks

As noted in the comment, make sure the name of your app is correct in the two appropriate lines above.

LikeMaBell
  • 1,529
  • 2
  • 13
  • 24
  • 1
    And to get the `heroku rake db:migrate` command to work, I also had to add `require 'rake/dsl_definition'` to the rakefile (above the require 'rake' line). – LikeMaBell Jul 01 '11 at 11:15
  • Doing all of this works for me, but isn't needed. The suggestion by NPatel handled it fine. – Scott Swezey Jul 02 '11 at 02:07
0

If you are seeing this on later versions of Rails (like 3.+) you may also want to verify that your environment is clean by using RVM http://beginrescueend.com/ and creating a specific ruby & gemset for your projects.

Use an .rvmrc file on a per-project basis, this will guarantee you aren't getting older system gems into your projects. Which has bitten me before.

This prevents having to monkey around with generated Rakefiles & such.

Jim Munro
  • 1,627
  • 1
  • 10
  • 8
0

bundle exec rake db:migrate will solve your ruby version issues

Galuga
  • 531
  • 2
  • 6
  • This only works if you have a working version of rake in your Gemfile, and typing "rake" is using some different version installed in your PATH – RyanHennig Nov 13 '12 at 23:03