Rails Rake任务电子邮件通知程序

时间:2012-10-01 15:08:54

标签: ruby-on-rails-3 rake actionmailer rake-task

我是编写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

感谢任何帮助。

1 个答案:

答案 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

http://railscasts.com/episodes/66-custom-rake-tasks

http://jasonseifer.com/2010/04/06/rake-tutorial