2012-06-26 63 views
0

(ROR使用Rails 3.1,寶石耙0.9.2.2)Rails:自定義Rake任務錯誤=> rake中止!丟失:控制器

我試圖運行最基本的自定義rake任務,你可以在這裏看到:

task :update_me => :environment do 

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

end 

我不斷收到下面的錯誤。如果我打印出hello world並取出「:environment」部分,該任務將運行。我的耙子任務似乎對這個「:environment」部分有問題,但我需要這個來訪問我的模型。

rake aborted! 
missing :controller 

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

跟蹤:

/home/ubuntu/.rvm/gems/[email protected]/gems/actionpack-3.2.3/lib/action_dispatch/routing/mapper.rb:179:in `default_controller_and_action' 
/home/ubuntu/.rvm/gems/[email protected]/gems/actionpack-3.2.3/lib/action_dispatch/routing/mapper.rb:76:in `normalize_options!' 
/home/ubuntu/.rvm/gems/[email protected]/gems/actionpack-3.2.3/lib/action_dispatch/routing/mapper.rb:59:in `initialize' 
/home/ubuntu/.rvm/gems/[email protected]/gems/actionpack-3.2.3/lib/action_dispatch/routing/mapper.rb:1302:in `new' 
/home/ubuntu/.rvm/gems/[email protected]/gems/actionpack-3.2.3/lib/action_dispatch/routing/mapper.rb:1302:in `add_route' 
/home/ubuntu/.rvm/gems/[email protected]/gems/actionpack-3.2.3/lib/action_dispatch/routing/mapper.rb:1282:in `decomposed_match' 
/home/ubuntu/.rvm/gems/[email protected]/gems/actionpack-3.2.3/lib/action_dispatch/routing/mapper.rb:1268:in `block in match' 
/home/ubuntu/.rvm/gems/[email protected]/gems/actionpack-3.2.3/lib/action_dispatch/routing/mapper.rb:1268:in `each' 
/home/ubuntu/.rvm/gems/[email protected]/gems/actionpack-3.2.3/lib/action_dispatch/routing/mapper.rb:1268:in `match' 
/home/ubuntu/.rvm/gems/[email protected]/gems/actionpack-3.2.3/lib/action_dispatch/routing/mapper.rb:505:in `map_method' 
/home/ubuntu/.rvm/gems/[email protected]/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/[email protected]/gems/actionpack-3.2.3/lib/action_dispatch/routing/route_set.rb:282:in `instance_exec' 
/home/ubuntu/.rvm/gems/[email protected]/gems/actionpack-3.2.3/lib/action_dispatch/routing/route_set.rb:282:in `eval_block' 
/home/ubuntu/.rvm/gems/[email protected]/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/[email protected]/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:245:in `load' 
/home/ubuntu/.rvm/gems/[email protected]/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:245:in `block in load' 
/home/ubuntu/.rvm/gems/[email protected]/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:236:in `load_dependency' 
/home/ubuntu/.rvm/gems/[email protected]/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:245:in `load' 
/home/ubuntu/.rvm/gems/[email protected]/gems/railties-3.2.3/lib/rails/application/routes_reloader.rb:40:in `block in load_paths' 
/home/ubuntu/.rvm/gems/[email protected]/gems/railties-3.2.3/lib/rails/application/routes_reloader.rb:40:in `each' 
/home/ubuntu/.rvm/gems/[email protected]/gems/railties-3.2.3/lib/rails/application/routes_reloader.rb:40:in `load_paths' 
/home/ubuntu/.rvm/gems/[email protected]/gems/railties-3.2.3/lib/rails/application/routes_reloader.rb:16:in `reload!' 
/home/ubuntu/.rvm/gems/[email protected]/gems/railties-3.2.3/lib/rails/application/routes_reloader.rb:26:in `block in updater' 
/home/ubuntu/.rvm/gems/[email protected]/gems/activesupport-3.2.3/lib/active_support/file_update_checker.rb:78:in `call' 
/home/ubuntu/.rvm/gems/[email protected]/gems/activesupport-3.2.3/lib/active_support/file_update_checker.rb:78:in `execute' 
/home/ubuntu/.rvm/gems/[email protected]/gems/railties-3.2.3/lib/rails/application/routes_reloader.rb:27:in `updater' 
/home/ubuntu/.rvm/gems/[email protected]/gems/railties-3.2.3/lib/rails/application/routes_reloader.rb:7:in `execute_if_updated' 
/home/ubuntu/.rvm/gems/[email protected]/gems/railties-3.2.3/lib/rails/application/finisher.rb:66:in `block in <module:Finisher>' 
/home/ubuntu/.rvm/gems/[email protected]/gems/railties-3.2.3/lib/rails/initializable.rb:30:in `instance_exec' 
/home/ubuntu/.rvm/gems/[email protected]/gems/railties-3.2.3/lib/rails/initializable.rb:30:in `run' 
/home/ubuntu/.rvm/gems/[email protected]/gems/railties-3.2.3/lib/rails/initializable.rb:55:in `block in run_initializers' 
/home/ubuntu/.rvm/gems/[email protected]/gems/railties-3.2.3/lib/rails/initializable.rb:54:in `each' 
/home/ubuntu/.rvm/gems/[email protected]/gems/railties-3.2.3/lib/rails/initializable.rb:54:in `run_initializers' 
/home/ubuntu/.rvm/gems/[email protected]/gems/railties-3.2.3/lib/rails/application.rb:136:in `initialize!' 
/home/ubuntu/.rvm/gems/[email protected]/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/[email protected]/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:251:in `require' 
/home/ubuntu/.rvm/gems/[email protected]/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:251:in `block in require' 
/home/ubuntu/.rvm/gems/[email protected]/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:236:in `load_dependency' 
/home/ubuntu/.rvm/gems/[email protected]/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:251:in `require' 
/home/ubuntu/.rvm/gems/[email protected]/gems/railties-3.2.3/lib/rails/application.rb:103:in `require_environment!' 
/home/ubuntu/.rvm/gems/[email protected]/gems/railties-3.2.3/lib/rails/application.rb:292:in `block (2 levels) in initialize_tasks' 
/home/ubuntu/.rvm/gems/[email protected]/gems/rake-0.9.2.2/lib/rake/task.rb:205:in `call' 
/home/ubuntu/.rvm/gems/[email protected]/gems/rake-0.9.2.2/lib/rake/task.rb:205:in `block in execute' 
/home/ubuntu/.rvm/gems/[email protected]/gems/rake-0.9.2.2/lib/rake/task.rb:200:in `each' 
/home/ubuntu/.rvm/gems/[email protected]/gems/rake-0.9.2.2/lib/rake/task.rb:200:in `execute' 
/home/ubuntu/.rvm/gems/[email protected]/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/[email protected]/gems/rake-0.9.2.2/lib/rake/task.rb:151:in `invoke_with_call_chain' 
/home/ubuntu/.rvm/gems/[email protected]/gems/rake-0.9.2.2/lib/rake/task.rb:176:in `block in invoke_prerequisites' 
/home/ubuntu/.rvm/gems/[email protected]/gems/rake-0.9.2.2/lib/rake/task.rb:174:in `each' 
/home/ubuntu/.rvm/gems/[email protected]/gems/rake-0.9.2.2/lib/rake/task.rb:174:in `invoke_prerequisites' 
/home/ubuntu/.rvm/gems/[email protected]/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/[email protected]/gems/rake-0.9.2.2/lib/rake/task.rb:151:in `invoke_with_call_chain' 
/home/ubuntu/.rvm/gems/[email protected]/gems/rake-0.9.2.2/lib/rake/task.rb:144:in `invoke' 
/home/ubuntu/.rvm/gems/[email protected]/gems/rake-0.9.2.2/lib/rake/application.rb:116:in `invoke_task' 
/home/ubuntu/.rvm/gems/[email protected]/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `block (2 levels) in top_level' 
/home/ubuntu/.rvm/gems/[email protected]/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `each' 
/home/ubuntu/.rvm/gems/ruby-1.9.2-p290[email protected]/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `block in top_level' 
/home/ubuntu/.rvm/gems/[email protected]/gems/rake-0.9.2.2/lib/rake/application.rb:133:in `standard_exception_handling' 
/home/ubuntu/.rvm/gems/[email protected]/gems/rake-0.9.2.2/lib/rake/application.rb:88:in `top_level' 
/home/ubuntu/.rvm/gems/[email protected]/gems/rake-0.9.2.2/lib/rake/application.rb:66:in `block in run' 
/home/ubuntu/.rvm/gems/[email protected]/gems/rake-0.9.2.2/lib/rake/application.rb:133:in `standard_exception_handling' 
/home/ubuntu/.rvm/gems/[email protected]/gems/rake-0.9.2.2/lib/rake/application.rb:63:in `run' 
/home/ubuntu/.rvm/gems/[email protected]/gems/rake-0.9.2.2/bin/rake:33:in `<top (required)>' 
/home/ubuntu/.rvm/gems/[email protected]/bin/rake:19:in `load' 
/home/ubuntu/.rvm/gems/[email protected]/bin/rake:19:in `<main>' 
+1

您的環境中似乎存在路由錯誤。當你運行'rake routes'時會發生什麼? – alf

+0

哦,我的路線文件有問題。謝謝!!! – heebee313

+0

@joetesia酷! :)我將它添加爲答案,以便您可以關閉該問題。 – alf

回答

2

回溯似乎表明在routes文件,當你需要的環境中加載錯誤。

在這些情況下,運行rake routes將帶來有關該問題的更多信息。