如何创建rake任务以删除超过30天的所有邮件?我有邮箱宝石。
我试着通过这样做来测试它:
desc "Remove message older than a day"
task :remove_old_notifications => :environment do
Notification.delete_all ["created_at < ?", 1.day.ago]
end
但它确实需要采取任何行动。我在/ lib / tasks中有文件
答案 0 :(得分:1)
你需要把它放在notifications.rake文件或类似的东西(扩展名需要.rake)。之后,它将在
中显示出来rake -T
输出,您可以使用
运行它rake remove_old_notifications