Rails:自定义Rake任务错误=>耙子流产了!失踪:控制器

时间:2012-06-26 22:59:44

标签: ruby-on-rails-3 rake environment rake-task

(RoR with Rails 3.1,gem rake 0.9.2.2)

我正在尝试运行最基本的自定义rake任务,如您所见:

task :update_me => :environment do

Product.all.each do |product|
        puts product.link
end

end

我一直收到以下错误。如果我打印出hello world并取出“:environment”部分,任务就会运行。我的rake任务似乎遇到了“环境”部分的问题,但我需要这个来访问我的模型。

rake aborted!
missing :controller

Tasks: TOP => update_me => environment
(See full trace by running task with --trace)

迹:

/home/ubuntu/.rvm/gems/ruby-1.9.2-p290@rails31/gems/actionpack-3.2.3/lib/action_dispatch/routing/mapper.rb:179:in `default_controller_and_action'
/home/ubuntu/.rvm/gems/ruby-1.9.2-p290@rails31/gems/actionpack-3.2.3/lib/action_dispatch/routing/mapper.rb:76:in `normalize_options!'
/home/ubuntu/.rvm/gems/ruby-1.9.2-p290@rails31/gems/actionpack-3.2.3/lib/action_dispatch/routing/mapper.rb:59:in `initialize'
/home/ubuntu/.rvm/gems/ruby-1.9.2-p290@rails31/gems/actionpack-3.2.3/lib/action_dispatch/routing/mapper.rb:1302:in `new'
/home/ubuntu/.rvm/gems/ruby-1.9.2-p290@rails31/gems/actionpack-3.2.3/lib/action_dispatch/routing/mapper.rb:1302:in `add_route'
/home/ubuntu/.rvm/gems/ruby-1.9.2-p290@rails31/gems/actionpack-3.2.3/lib/action_dispatch/routing/mapper.rb:1282:in `decomposed_match'
/home/ubuntu/.rvm/gems/ruby-1.9.2-p290@rails31/gems/actionpack-3.2.3/lib/action_dispatch/routing/mapper.rb:1268:in `block in match'
/home/ubuntu/.rvm/gems/ruby-1.9.2-p290@rails31/gems/actionpack-3.2.3/lib/action_dispatch/routing/mapper.rb:1268:in `each'
/home/ubuntu/.rvm/gems/ruby-1.9.2-p290@rails31/gems/actionpack-3.2.3/lib/action_dispatch/routing/mapper.rb:1268:in `match'
/home/ubuntu/.rvm/gems/ruby-1.9.2-p290@rails31/gems/actionpack-3.2.3/lib/action_dispatch/routing/mapper.rb:505:in `map_method'
/home/ubuntu/.rvm/gems/ruby-1.9.2-p290@rails31/gems/actionpack-3.2.3/lib/action_dispatch/routing/mapper.rb:467:in `get'
/home/ubuntu/code/preevio/config/routes.rb:35:in `block in <top (required)>'
/home/ubuntu/.rvm/gems/ruby-1.9.2-p290@rails31/gems/actionpack-3.2.3/lib/action_dispatch/routing/route_set.rb:282:in `instance_exec'
/home/ubuntu/.rvm/gems/ruby-1.9.2-p290@rails31/gems/actionpack-3.2.3/lib/action_dispatch/routing/route_set.rb:282:in `eval_block'
/home/ubuntu/.rvm/gems/ruby-1.9.2-p290@rails31/gems/actionpack-3.2.3/lib/action_dispatch/routing/route_set.rb:260:in `draw'
/home/ubuntu/code/preevio/config/routes.rb:1:in `<top (required)>'
/home/ubuntu/.rvm/gems/ruby-1.9.2-p290@rails31/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:245:in `load'
/home/ubuntu/.rvm/gems/ruby-1.9.2-p290@rails31/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:245:in `block in load'
/home/ubuntu/.rvm/gems/ruby-1.9.2-p290@rails31/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:236:in `load_dependency'
/home/ubuntu/.rvm/gems/ruby-1.9.2-p290@rails31/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:245:in `load'
/home/ubuntu/.rvm/gems/ruby-1.9.2-p290@rails31/gems/railties-3.2.3/lib/rails/application/routes_reloader.rb:40:in `block in load_paths'
/home/ubuntu/.rvm/gems/ruby-1.9.2-p290@rails31/gems/railties-3.2.3/lib/rails/application/routes_reloader.rb:40:in `each'
/home/ubuntu/.rvm/gems/ruby-1.9.2-p290@rails31/gems/railties-3.2.3/lib/rails/application/routes_reloader.rb:40:in `load_paths'
/home/ubuntu/.rvm/gems/ruby-1.9.2-p290@rails31/gems/railties-3.2.3/lib/rails/application/routes_reloader.rb:16:in `reload!'
/home/ubuntu/.rvm/gems/ruby-1.9.2-p290@rails31/gems/railties-3.2.3/lib/rails/application/routes_reloader.rb:26:in `block in updater'
/home/ubuntu/.rvm/gems/ruby-1.9.2-p290@rails31/gems/activesupport-3.2.3/lib/active_support/file_update_checker.rb:78:in `call'
/home/ubuntu/.rvm/gems/ruby-1.9.2-p290@rails31/gems/activesupport-3.2.3/lib/active_support/file_update_checker.rb:78:in `execute'
/home/ubuntu/.rvm/gems/ruby-1.9.2-p290@rails31/gems/railties-3.2.3/lib/rails/application/routes_reloader.rb:27:in `updater'
/home/ubuntu/.rvm/gems/ruby-1.9.2-p290@rails31/gems/railties-3.2.3/lib/rails/application/routes_reloader.rb:7:in `execute_if_updated'
/home/ubuntu/.rvm/gems/ruby-1.9.2-p290@rails31/gems/railties-3.2.3/lib/rails/application/finisher.rb:66:in `block in <module:Finisher>'
/home/ubuntu/.rvm/gems/ruby-1.9.2-p290@rails31/gems/railties-3.2.3/lib/rails/initializable.rb:30:in `instance_exec'
/home/ubuntu/.rvm/gems/ruby-1.9.2-p290@rails31/gems/railties-3.2.3/lib/rails/initializable.rb:30:in `run'
/home/ubuntu/.rvm/gems/ruby-1.9.2-p290@rails31/gems/railties-3.2.3/lib/rails/initializable.rb:55:in `block in run_initializers'
/home/ubuntu/.rvm/gems/ruby-1.9.2-p290@rails31/gems/railties-3.2.3/lib/rails/initializable.rb:54:in `each'
/home/ubuntu/.rvm/gems/ruby-1.9.2-p290@rails31/gems/railties-3.2.3/lib/rails/initializable.rb:54:in `run_initializers'
/home/ubuntu/.rvm/gems/ruby-1.9.2-p290@rails31/gems/railties-3.2.3/lib/rails/application.rb:136:in `initialize!'
/home/ubuntu/.rvm/gems/ruby-1.9.2-p290@rails31/gems/railties-3.2.3/lib/rails/railtie/configurable.rb:30:in `method_missing'
/home/ubuntu/code/preevio/config/environment.rb:5:in `<top (required)>'
/home/ubuntu/.rvm/gems/ruby-1.9.2-p290@rails31/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:251:in `require'
/home/ubuntu/.rvm/gems/ruby-1.9.2-p290@rails31/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:251:in `block in require'
/home/ubuntu/.rvm/gems/ruby-1.9.2-p290@rails31/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:236:in `load_dependency'
/home/ubuntu/.rvm/gems/ruby-1.9.2-p290@rails31/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:251:in `require'
/home/ubuntu/.rvm/gems/ruby-1.9.2-p290@rails31/gems/railties-3.2.3/lib/rails/application.rb:103:in `require_environment!'
/home/ubuntu/.rvm/gems/ruby-1.9.2-p290@rails31/gems/railties-3.2.3/lib/rails/application.rb:292:in `block (2 levels) in initialize_tasks'
/home/ubuntu/.rvm/gems/ruby-1.9.2-p290@rails31/gems/rake-0.9.2.2/lib/rake/task.rb:205:in `call'
/home/ubuntu/.rvm/gems/ruby-1.9.2-p290@rails31/gems/rake-0.9.2.2/lib/rake/task.rb:205:in `block in execute'
/home/ubuntu/.rvm/gems/ruby-1.9.2-p290@rails31/gems/rake-0.9.2.2/lib/rake/task.rb:200:in `each'
/home/ubuntu/.rvm/gems/ruby-1.9.2-p290@rails31/gems/rake-0.9.2.2/lib/rake/task.rb:200:in `execute'
/home/ubuntu/.rvm/gems/ruby-1.9.2-p290@rails31/gems/rake-0.9.2.2/lib/rake/task.rb:158:in `block in invoke_with_call_chain'
/home/ubuntu/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/monitor.rb:201:in `mon_synchronize'
/home/ubuntu/.rvm/gems/ruby-1.9.2-p290@rails31/gems/rake-0.9.2.2/lib/rake/task.rb:151:in `invoke_with_call_chain'
/home/ubuntu/.rvm/gems/ruby-1.9.2-p290@rails31/gems/rake-0.9.2.2/lib/rake/task.rb:176:in `block in invoke_prerequisites'
/home/ubuntu/.rvm/gems/ruby-1.9.2-p290@rails31/gems/rake-0.9.2.2/lib/rake/task.rb:174:in `each'
/home/ubuntu/.rvm/gems/ruby-1.9.2-p290@rails31/gems/rake-0.9.2.2/lib/rake/task.rb:174:in `invoke_prerequisites'
/home/ubuntu/.rvm/gems/ruby-1.9.2-p290@rails31/gems/rake-0.9.2.2/lib/rake/task.rb:157:in `block in invoke_with_call_chain'
/home/ubuntu/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/monitor.rb:201:in `mon_synchronize'
/home/ubuntu/.rvm/gems/ruby-1.9.2-p290@rails31/gems/rake-0.9.2.2/lib/rake/task.rb:151:in `invoke_with_call_chain'
/home/ubuntu/.rvm/gems/ruby-1.9.2-p290@rails31/gems/rake-0.9.2.2/lib/rake/task.rb:144:in `invoke'
/home/ubuntu/.rvm/gems/ruby-1.9.2-p290@rails31/gems/rake-0.9.2.2/lib/rake/application.rb:116:in `invoke_task'
/home/ubuntu/.rvm/gems/ruby-1.9.2-p290@rails31/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `block (2 levels) in top_level'
/home/ubuntu/.rvm/gems/ruby-1.9.2-p290@rails31/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `each'
/home/ubuntu/.rvm/gems/ruby-1.9.2-p290@rails31/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `block in top_level'
/home/ubuntu/.rvm/gems/ruby-1.9.2-p290@rails31/gems/rake-0.9.2.2/lib/rake/application.rb:133:in `standard_exception_handling'
/home/ubuntu/.rvm/gems/ruby-1.9.2-p290@rails31/gems/rake-0.9.2.2/lib/rake/application.rb:88:in `top_level'
/home/ubuntu/.rvm/gems/ruby-1.9.2-p290@rails31/gems/rake-0.9.2.2/lib/rake/application.rb:66:in `block in run'
/home/ubuntu/.rvm/gems/ruby-1.9.2-p290@rails31/gems/rake-0.9.2.2/lib/rake/application.rb:133:in `standard_exception_handling'
/home/ubuntu/.rvm/gems/ruby-1.9.2-p290@rails31/gems/rake-0.9.2.2/lib/rake/application.rb:63:in `run'
/home/ubuntu/.rvm/gems/ruby-1.9.2-p290@rails31/gems/rake-0.9.2.2/bin/rake:33:in `<top (required)>'
/home/ubuntu/.rvm/gems/ruby-1.9.2-p290@rails31/bin/rake:19:in `load'
/home/ubuntu/.rvm/gems/ruby-1.9.2-p290@rails31/bin/rake:19:in `<main>'

1 个答案:

答案 0 :(得分:2)

回溯似乎表明路由文件中存在错误,该错误在您需要环境时加载。

在这些情况下,运行rake routes会提供有关此问题的更多信息。