我的簡單rake任務存儲在lib/tasks/items_spider.rake
中,運行良好。它的全部功能是在Item
型號上撥打spider!
。Rails 3 rake任務在生產中找不到型號
namespace :items do
desc "Spider the web for data, hoorah"
task :spider => :environment do
Item.spider!
end
end
我有:environment
任務作爲依賴,所以一切都工作得很好。然而,當我加RAILS_ENV=production
,我打的錯誤,無論是我的本地服務器和生產服務器上:
$ rake items:spider RAILS_ENV=production --trace
(in /home/matchu/Websites/my-rails-app)
** Invoke items:spider (first_time)
** Invoke environment (first_time)
** Execute environment
** Execute items:spider
rake aborted!
uninitialized constant Object::Item
/home/matchu/.rvm/gems/[email protected]/gems/rake-0.8.7/lib/rake.rb:2503:in `const_missing'
/home/matchu/.rvm/gems/[email protected]/gems/rspec-core-2.0.0.beta.22/lib/rspec/core/backward_compatibility.rb:20:in `const_missing'
/home/matchu/.rvm/gems/[email protected]/gems/rspec-expectations-2.0.0.beta.22/lib/rspec/expectations/backward_compatibility.rb:6:in `const_missing'
/home/matchu/Websites/openneo-impress-items/lib/tasks/items_spider.rake:4:in `block (2 levels) in <top (required)>'
/home/matchu/.rvm/gems/[email protected]/gems/rake-0.8.7/lib/rake.rb:636:in `call'
[...trace of how rake gets to my task...]
這似乎只是奇怪了吧。顯然這些模型尚未正確加載。我使用的是Rails 3.0.3,但是當Rails 3處於測試階段時,此應用程序的開發就開始了。我如何去調試這個問題?謝謝!
這裏到達了一下(注意!這應該config.threadsafe呼叫後加入),但你有沒有嘗試過的RAILS_ENV聲明移動到命令的開始? – 2010-11-29 02:09:55
@Peer:no go :(謝謝! – Matchu 2010-11-29 02:16:34
「Item」模型在哪裏?通常的位置? – 2010-11-29 03:02:35