0

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

任何帮助表示赞赏。

4

1 回答 1

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

于 2012-10-01T15:23:42.340 回答