2010-05-07 53 views
2

我想從一個將遠程天氣數據存儲在rails緩存中的cron作業調用rake任務。但是,我必須在這裏做一些非常錯誤的事情,因爲我無法通過無數次無果的搜索找到任何解決方案。rake任務無法訪問rails.cache

說我定義和調用這個任務

namespace :weather do 
    desc "Store weather from remote source to cache" 
    task :cache do 
    Rails.cache.write('weather_data', Date.today) 
    end 
end 

我得到的錯誤

Anonymous modules have no name to be referenced by 

這使我相信軌道緩存不可用。從rake文件輸出Rails.class給了我Module,但Rails.cache.class再次返回上面的錯誤。我需要在這裏包括什麼嗎?我只是在互聯網上絕望嗎? :)

在此先感謝。

回答

6

嘗試通過在軌環境

task (:cache => :environment) do 
    ... 
end 

好像你會得到一個不同的錯誤,但我會嘗試這個