使用 Rake 0.9.0 的未定义方法“任务" [英] Undefined method 'task' using Rake 0.9.0
问题描述
我刚刚将 Rake 更新到最新版本 (0.9.0.beta.4
) 和 rake
命令结束时出现以下错误消息:
I just updated Rake to the latest version (0.9.0.beta.4
) and the rake
command ends up with the following error message:
rake aborted!
undefined method `task' for #<Anelis::Application:0x9223b6c>
这是跟踪:
undefined method `task' for #<Anelis::Application:0x97ef80c>
/usr/local/rvm/gems/ruby-1.9.2-p136/gems/railties-3.0.3/lib/rails/application.rb:214:in `initialize_tasks'
/usr/local/rvm/gems/ruby-1.9.2-p136/gems/railties-3.0.3/lib/rails/application.rb:139:in `load_tasks'
/usr/local/rvm/gems/ruby-1.9.2-p136/gems/railties-3.0.3/lib/rails/application.rb:77:in `method_missing'
/home/amokrane/Documents/prog/web/learning_rails/anelis/Rakefile:7:in `load_string'
/usr/local/rvm/gems/ruby-1.9.2-p136/gems/rake-0.9.0.beta.4/lib/rake/environment.rb:28:in `eval'
/usr/local/rvm/gems/ruby-1.9.2-p136/gems/rake-0.9.0.beta.4/lib/rake/environment.rb:28:in `load_string'
/usr/local/rvm/gems/ruby-1.9.2-p136/gems/rake-0.9.0.beta.4/lib/rake/environment.rb:16:in `load_rakefile'
/usr/local/rvm/gems/ruby-1.9.2-p136/gems/rake-0.9.0.beta.4/lib/rake/application.rb:495:in `raw_load_rakefile'
/usr/local/rvm/gems/ruby-1.9.2-p136/gems/rake-0.9.0.beta.4/lib/rake/application.rb:78:in `block in load_rakefile'
/usr/local/rvm/gems/ruby-1.9.2-p136/gems/rake-0.9.0.beta.4/lib/rake/application.rb:129:in `standard_exception_handling'
/usr/local/rvm/gems/ruby-1.9.2-p136/gems/rake-0.9.0.beta.4/lib/rake/application.rb:77:in `load_rakefile'
/usr/local/rvm/gems/ruby-1.9.2-p136/gems/rake-0.9.0.beta.4/lib/rake/application.rb:61:in `block in run'
/usr/local/rvm/gems/ruby-1.9.2-p136/gems/rake-0.9.0.beta.4/lib/rake/application.rb:129:in `standard_exception_handling'
/usr/local/rvm/gems/ruby-1.9.2-p136/gems/rake-0.9.0.beta.4/lib/rake/application.rb:59:in `run'
/usr/local/rvm/gems/ruby-1.9.2-p136/gems/rake-0.9.0.beta.4/bin/rake:31:in `<top (required)>'
/usr/local/rvm/gems/ruby-1.9.2-p136/bin/rake:19:in `load'
/usr/local/rvm/gems/ruby-1.9.2-p136/bin/rake:19:in `<main>'
有人遇到过同样的问题吗?可能有什么问题?请注意,我正在运行 Rails 3.0.3
,您可能还对我的 Gemfile 的内容感兴趣:
Anyone experienced the same issue? What could possibly be wrong? Note that I am running Rails 3.0.3
, you may also be interested in the content of my Gemfile:
source 'http://rubygems.org'
gem 'rails', '3.0.3'
gem 'sqlite3-ruby', :require => 'sqlite3'
gem 'mysql2'
gem 'legacy_data'
gem 'resources_controller', :git => 'git://github.com/ianwhite/resources_controller'
gem 'will_paginate', '3.0.pre' # pagination
gem 'jquery-rails', '>= 0.2.6'
gem "rmagick" # sudo aptitude install libmagick9-dev
gem "paperclip", "~> 2.3"
gem "nested_form", :git => "git://github.com/madebydna/nested_form.git"
gem "meta_search"
gem "hirb"
gem "devise"
gem "rails_admin", :git => "git://github.com/sferik/rails_admin.git"
我该如何解决这个问题?
How can I fix this problem?
推荐答案
我在运行 0.9.0.beta.4 版本的 Rake 时遇到了同样的异常.看起来新的 Rake::DSL
没有正确加载.
I had the same exception when running the 0.9.0.beta.4 version of Rake.
It looks like the new Rake::DSL
is not loaded properly.
所以我在我的 Rakefile 中添加了以下代码:
So I added following code to my Rakefile:
require 'rake'
# Rake Fix Code start
# NOTE: change 'Anelis' to your app's module name (see config/application.rb)
module ::Anelis
class Application
include Rake::DSL
end
end
module ::RakeFileUtils
extend Rake::FileUtilsExt
end
# Rake Fix Code end
MyApp::Application.load_tasks
这样我就可以再次运行我的 Rake 任务了.
That way I was able to run my Rake tasks again.
我知道这不是一个优雅的解决方案.但是如果你必须使用 Rake 的 --pre
版本,使用这个快速的 hack 可能没问题.
I know that this is not a elegant solution. But if you have to use the --pre
version of Rake it might be all right to use this quick hack.
这篇关于使用 Rake 0.9.0 的未定义方法“任务"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!