Ruby on Rails 和 Rake 问题:未初始化的常量 Rake::DSL
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6085610/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Ruby on Rails and Rake problems: uninitialized constant Rake::DSL
提问by HRóDóLFR
I'm having a really frustrating issue: Rakeis being dumb.
我遇到了一个非常令人沮丧的问题:Rake很笨。
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?
我该如何解决这个问题?
回答by Caley Woods
A tweet from DHHearlier. Rake .9.0 breaks Rails and several other things, you need to:
DHH早些时候的一条推文。Rake .9.0 破坏了 Rails 和其他一些东西,你需要:
gem "rake", "0.8.7"
in your Gemfile.
在你的 Gemfile 中。
回答by Arrumaco
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:
所有问题都用 Rake gem 0.9.2 解决了。我按照以下步骤操作:
- 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:migrateshowed 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 endI ommited the
module ::RakeFileUtils extend Rake::FileUtilsExtendoption sugested by @databyte.
- 我安装了
gem install rake -v=0.9.2(我有 0.9.1 gem) - 删除了 0.9.1
gem uninstall rake -v=0.9.1 - 更新为
bundle update 然后
db:migrate显示了警告,WARNING: Global access to Rake DSL methods is deprecated. Please....它是通过将以下内容添加到 Rake 文件中解决的。
module ::YourApplicationName class Application include Rake::DSL end end我省略了@databyte 建议的
module ::RakeFileUtils extend Rake::FileUtilsExtend选项。
It means that the Rake gem 0.9.2 works fine!
这意味着 Rake gem 0.9.2 工作正常!
回答by djblue2009
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:
阅读 Railstutorial (demo_app) 的第 2 章并遇到了这个问题。我尝试了此处列出的所有其他答案,但在我这样做之前无法让它发挥作用:
Put this in your Rakefile above require 'rake':
把它放在你的 Rakefile 上面 require 'rake':
require 'rake/dsl_definition'
via How to fix the uninitialized constant Rake::DSL problem on Heroku?
通过如何修复 Heroku 上未初始化的常量 Rake::DSL 问题?
I also recommitted and pushed all files to Github and Heroku.
我还重新提交并将所有文件推送到 Github 和 Heroku。
回答by Branstar
All I needed to do was use:
我需要做的就是使用:
gem install rake
I had version 0.9.2 already, just needed installing.
我已经有了 0.9.2 版本,只需要安装。
回答by hohner
Reinstall the rake gem and it shouldwork fine:
重新安装 rake gem,它应该可以正常工作:
gem uninstall rake -v=0.9.2
gem install rake -v=0.9.2
If not, specify version '0.8.7' in your Gemfile.
如果没有,请在您的 Gemfile 中指定版本 '0.8.7'。
回答by Travis Reeder
If not using Bundler:
如果不使用 Bundler:
sudo gem install rake -v 0.8.7
sudo gem uninstall rake
Then choose to uninstall 0.9.0.
然后选择卸载0.9.0。
回答by Jonathon Horsman
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
如果像我一样你被困在 rake 0.8.7 上,并且你使用的是 Rails 3.2.x,那么 railties 会增加对 Rake::DSL 的要求
To solve this, to the top of your Rakefile you should add:
要解决这个问题,您应该在 Rakefile 的顶部添加:
module Rake
module DSL
end
end
回答by Gaurav Gupta
I solved the same problem with the following steps:
我通过以下步骤解决了同样的问题:
In Gemfile:
在 Gemfile 中:
gem 'rake', '0.9.2'
Then ran this on the console:
然后在控制台上运行:
sudo bundle update rake
Then added the following lines to Rakefile:
然后将以下几行添加到 Rakefile:
require 'rake/dsl_definition'
include Rake::DSL
回答by databyte
Rails 3.1.rc1 has been updated. For your own Rakefiles, you can add this before the call to load_tasks.
Rails 3.1.rc1 已更新。对于您自己的 Rakefile,您可以在调用 load_tasks 之前添加它。
module ::YourApplicationName
class Application
include Rake::DSL
end
end
module ::RakeFileUtils
extend Rake::FileUtilsExt
end
https://gist.github.com/4cd2bbe68f98f2f0249f
https://gist.github.com/4cd2bbe68f98f2f0249f
UPDATE: Also noticed it's already answered here as well: Undefined method 'task' using Rake 0.9.0
更新:还注意到这里也已经回答了:使用 Rake 0.9.0 的未定义方法“任务”
回答by Paul
I had the same issue and had to use the rake 0.8.7 gem instead of 0.9.0.
我遇到了同样的问题,不得不使用 rake 0.8.7 gem 而不是 0.9.0。

