我是编写Rails rake任务的新手。我想编写一个rake任务,查找在30分钟到期并执行邮件程序的调用。下面是我将从控制器中使用的代码,如何将其调整为我的rake任务?
@call = Call.find(params[:id])
if Time.zone.now < @call.transfer_date + 30.minutes
@call.units.each do |unit|
CallMailer.cancel_call(unit.incharge, @call).deliver
CallMailer.cancel_call(unit.attendant, @call).deliver
end
end
感谢任何帮助。
答案 0 :(得分:0)
namespace :send_due_emails do
desc "" #task describtion
task :send_due_emails_task => :environment do
send_emails
end
def send_emails
@call = Call.find(params[:id])
if Time.zone.now < @call.transfer_date + 30.minutes
@call.units.each do |unit|
CallMailer.cancel_call(unit.incharge, @call).deliver
CallMailer.cancel_call(unit.attendant, @call).deliver
end
end
end
end