耙子宝石问题
我有这个 ruby on Rails 项目,我想做 db:migrate。但我得到的唯一 rake 选项是“重新加载 rake 任务”,所以当我点击该选项时,它会给我这个错误。
[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
谢谢,迈克尔。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是一个常见问题。只需按照以下步骤操作:
gem install rake -v=0.9.2
(如果您有 0.9.1 gem)gem uninstall rake -v=0.9.1
(如果您有有 0.9.1 gem)查看您的日志,我发现您有
rake-0.9.2
所以我认为您可以跳过上面的 2 个步骤。bundle update
然后,运行
db:migrate
会出现如下错误:警告:不推荐对 Rake DSL 方法的全局访问
要解决此问题,您只需将这两行添加到 Rakefile 的顶部
require 'rake/dsl_definition'
include Rake::DSL
它应该可以工作完美之后就好了!
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!
您应该在 Gemfile 中特别添加 Rake 版本 >= 0.9.1!
某些 Rails 3 版本存在一个错误,当您使用较旧的 Rake 版本时,您会看到类似这样的奇怪错误。
在您的 Gemfile 中:
我还建议您专门为您的应用程序创建一个新的 gemset,例如
:
对于新的 gemset,您可能必须手动添加“gem install rake”,然后运行“bundle install”
在中使用单独的 gemset除了使用 Gemfile 之外,保持项目中 gem 版本稳定并与其他项目解耦的最佳方法。
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:
I'd also recommend you create a new gemset specifically for your application, e.g.
or:
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.