2014-03-24 55 views
1

如何創建刪除任何超過30天的消息的rake任務?我有郵箱寶石。創建rake任務以刪除x天以前的消息

我試圖做測試它:

desc "Remove message older than a day" 
task :remove_old_notifications => :environment do 
Notification.delete_all ["created_at < ?", 1.day.ago] 
end 

但是它並採取任何行動。我有文件裏面的/ lib /任務

+0

你是怎麼調用該文件運行呢?你是如何嘗試執行它的? – lurker

+0

您的rake任務是否正在執行或正在執行,但記錄沒有被刪除? –

回答

1

你需要把它放在notifications.rake文件或類似的東西(擴展名需要是.rake)。之後,它會在

rake -T 

輸出是可見的,你就可以使用

rake remove_old_notifications