我开始学习如何使用rake任务我的第一个rake任务是显示“Hello World”
tasks :greet do
puts "Hello World"
end
但由于某种原因,我有以下错误
$ rails -v
Rails 3.2.12
$ ruby -v
ruby 2.0.0p247 (2013-06-27 revision 41674) [x86_64-darwin12.5.0]
$ gem -v
2.0.3
这是我正在使用的命令:
$ rake greet --trace
rake aborted!
undefined method `tasks' for main:Object
/Users/jcr/web/examen-dev/lib/tasks/myfirst.rake:1:in `<top (required)>'
/Users/jcr/.rvm/gems/ruby-2.0.0-p247/gems/activesupport-3.2.12/lib/active_support/dependencies.rb:245:in `load'
/Users/jcr/.rvm/gems/ruby-2.0.0-p247/gems/activesupport-3.2.12/lib/active_support/dependencies.rb:245:in `block in load'
/Users/jcr/.rvm/gems/ruby-2.0.0-p247/gems/activesupport-3.2.12/lib/active_support/dependencies.rb:236:in `load_dependency'
/Users/jcr/.rvm/gems/ruby-2.0.0-p247/gems/activesupport-
3.2.12/lib/active_support/dependencies.rb:245:in `load'
/Users/jcr/.rvm/gems/ruby-2.0.0-p247/gems/railties-3.2.12/lib/rails/engine.rb:425:in `block in load_tasks'
/Users/jcr/.rvm/gems/ruby-2.0.0-p247/gems/railties-3.2.12/lib/rails/engine.rb:425:in `each'
/Users/jcr/.rvm/gems/ruby-2.0.0-p247/gems/railties-3.2.12/lib/rails/engine.rb:425:in `load_tasks'
/Users/jcr/.rvm/gems/ruby-2.0.0-p247/gems/railties-3.2.12/lib/rails/application.rb:145:in `load_tasks'
/Users/jcr/.rvm/gems/ruby-2.0.0-p247/gems/railties-3.2.12/lib/rails/railtie/configurable.rb:30:in `method_missing'
/Users/jcr/web/examen-dev/Rakefile:7:in `<top (required)>'
/Users/jcr/.rvm/gems/ruby-2.0.0-p247/gems/rake-10.1.0/lib/rake/rake_module.rb:25:in `load'
/Users/jcr/.rvm/gems/ruby-2.0.0-p247/gems/rake-10.1.0/lib/rake/rake_module.rb:25:in `load_rakefile'
/Users/jcr/.rvm/gems/ruby-2.0.0-p247/gems/rake-10.1.0/lib/rake/application.rb:637:in `raw_load_rakefile'
/Users/jcr/.rvm/gems/ruby-2.0.0-p247/gems/rake-10.1.0/lib/rake/application.rb:94:in `block in load_rakefile'
/Users/jcr/.rvm/gems/ruby-2.0.0-p247/gems/rake-10.1.0/lib/rake/application.rb:165:in `standard_exception_handling'
/Users/jcr/.rvm/gems/ruby-2.0.0-p247/gems/rake-10.1.0/lib/rake/application.rb:93:in `load_rakefile'
/Users/jcr/.rvm/gems/ruby-2.0.0-p247/gems/rake-10.1.0/lib/rake/application.rb:77:in `block in run'
/Users/jcr/.rvm/gems/ruby-2.0.0-p247/gems/rake-10.1.0/lib/rake/application.rb:165:in `standard_exception_handling'
/Users/jcr/.rvm/gems/ruby-2.0.0-p247/gems/rake-10.1.0/lib/rake/application.rb:75:in `run'
/Users/jcr/.rvm/gems/ruby-2.0.0-p247/gems/rake-10.1.0/bin/rake:33:in `<top (required)>'
/Users/jcr/.rvm/gems/ruby-2.0.0-p247/bin/rake:23:in `load'
/Users/jcr/.rvm/gems/ruby-2.0.0-p247/bin/rake:23:in `<main>'
请你给我一些建议来解决这个错误吗?
谢谢
答案 0 :(得分:1)
按任务替换任务,它应该有效!