Ruby on Rails and Rake problems: uninitialized con

2019-01-01 12:35发布

I'm having a really frustrating issue: Rake is being dumb.

Here's how the problem comes about:

$ rails new test_app
$ rails generate scaffold new_scaffold field1:string field2:text

Both of those work just fine, but then when I do this,

$ rake db:migrate

I get the following error.

(in /home/mikhail/test_app)
rake aborted!
uninitialized constant Rake::DSL
/usr/lib/ruby/1.9.1/rake.rb:2482:in `const_missing'
/usr/lib/ruby/gems/1.9.1/gems/rake-0.9.0/lib/rake/tasklib.rb:8:in `<class:TaskLib>'
/usr/lib/ruby/gems/1.9.1/gems/rake-0.9.0/lib/rake/tasklib.rb:6:in `<module:Rake>'
/usr/lib/ruby/gems/1.9.1/gems/rake-0.9.0/lib/rake/tasklib.rb:3:in `<top (required)>'
/usr/lib/ruby/gems/1.9.1/gems/rake-0.9.0/lib/rake/rdoctask.rb:20:in `require'
/usr/lib/ruby/gems/1.9.1/gems/rake-0.9.0/lib/rake/rdoctask.rb:20:in `<top (required)>'
/usr/lib/ruby/gems/1.9.1/gems/railties-3.0.7/lib/rails/tasks/documentation.rake:1:in `require'
/usr/lib/ruby/gems/1.9.1/gems/railties-3.0.7/lib/rails/tasks/documentation.rake:1:in `<top (required)>'
/usr/lib/ruby/gems/1.9.1/gems/railties-3.0.7/lib/rails/tasks.rb:15:in `load'
/usr/lib/ruby/gems/1.9.1/gems/railties-3.0.7/lib/rails/tasks.rb:15:in `block in <top (required)>'
/usr/lib/ruby/gems/1.9.1/gems/railties-3.0.7/lib/rails/tasks.rb:6:in `each'
/usr/lib/ruby/gems/1.9.1/gems/railties-3.0.7/lib/rails/tasks.rb:6:in `<top (required)>'
/usr/lib/ruby/gems/1.9.1/gems/railties-3.0.7/lib/rails/application.rb:214:in `require'
/usr/lib/ruby/gems/1.9.1/gems/railties-3.0.7/lib/rails/application.rb:214:in `initialize_tasks'
/usr/lib/ruby/gems/1.9.1/gems/railties-3.0.7/lib/rails/application.rb:139:in `load_tasks'
/usr/lib/ruby/gems/1.9.1/gems/railties-3.0.7/lib/rails/application.rb:77:in `method_missing'
/home/mikhail/test_app/Rakefile:7:in `<top (required)>'
/usr/lib/ruby/1.9.1/rake.rb:2373:in `load'
/usr/lib/ruby/1.9.1/rake.rb:2373:in `raw_load_rakefile'
/usr/lib/ruby/1.9.1/rake.rb:2007:in `block in load_rakefile'
/usr/lib/ruby/1.9.1/rake.rb:2058:in `standard_exception_handling'
/usr/lib/ruby/1.9.1/rake.rb:2006:in `load_rakefile'
/usr/lib/ruby/1.9.1/rake.rb:1991:in `run'
/usr/bin/rake:31:in `<main>'

I've looked about the Internet for similar/same errors, and people have had them. Just no one ever seems to solve the problem!

How do I fix this problem?

19条回答
低头抚发
2楼-- · 2019-01-01 12:45

For Rails 2.3 editing lib/tasks/rspec.rake like in this commit worked for me:

https://github.com/dchelimsky/rspec-rails/pull/11/files

查看更多
梦寄多情
3楼-- · 2019-01-01 12:47

Uninstalling with "gem uninstall rake" worked for me, I had 2 versions installed, so I jest did a clean reinstall.

"rake db:create", to make sure the database exists and then "rake db:migrate" to seal the deal.

查看更多
浅入江南
4楼-- · 2019-01-01 12:48

I am a Windows XP user and I had the same problem.

I entered gem "rake", "0.8.7" into the gemfile, and then typed the following from the command window.

bundle update rake

This fixed my problem.

查看更多
闭嘴吧你
5楼-- · 2019-01-01 12:49

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.

查看更多
明月照影归
6楼-- · 2019-01-01 12:52

All I needed to do was use:

gem install rake

I had version 0.9.2 already, just needed installing.

查看更多
宁负流年不负卿
7楼-- · 2019-01-01 12:53

If like me you're stuck on rake 0.8.7, and you're using Rails 3.2.x then railties adds a requirement for Rake::DSL

To solve this, to the top of your Rakefile you should add:

module Rake
  module DSL
  end
end
查看更多
登录 后发表回答