我在rails项目上有这个ruby,我想做db:migrate。但我唯一获得的rake选项是“Reload rake tasks”,所以当我点击它时,它会给我这个错误。
[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
谢谢,迈克尔。
答案 0 :(得分:3)
这是一个常见问题。只需按照以下步骤操作:
gem install rake -v=0.9.2
(如果你有0.9.1宝石)
gem uninstall rake -v=0.9.1
(如果你有0.9.1宝石)
查看您的日志,我看到您有rake-0.9.2
所以我认为您可以跳过上述两个步骤。
bundle update
然后,运行db:migrate
将会出现如下错误:WARNING: Global access to Rake DSL methods is deprecated
要解决此问题,您只需将这两行添加到Rakefile
require 'rake/dsl_definition'
include Rake::DSL
之后应该完美无缺!
答案 1 :(得分:1)
你应该在你的Gemfile中专门添加Rake版本> = 0.9.1! 某些Rails 3版本存在一个错误,当您使用较旧的Rake版本时,您会看到类似的奇怪错误。
在你的Gemfile中:
gem 'rake' , '>= 0.9.2'
我还建议您专门为您的应用程序创建一个新的gemset,例如
rvm gemset create yourproject
rvm gemset use yourproject
或:
rvm gemset use yourproject --default
对于新的gemset,你可能需要手动添加“gem install rake”,然后运行“bundle install”
除了使用Gemfile之外,使用单独的gemset是保持项目中的gem版本稳定并与其他项目分离的最佳方法。