1

我的报告控制器中有这个方法:

def send_status
 date = Date.today
 reports = current_user.reports.for_date(date)
 ReportMailer.status_email(current_user, reports, date).deliver
 reports.update_all(:sent_mail => true)
 head :ok
 rescue => e
 render text: e.message, status: :bad_request
end

发送此状态时我无法提出任何请求,因此我使用了延迟作业,替换

ReportMailer.status_email(current_user, reports, date).deliver with ReportMailer.status_email(current_user, reports, date).send_later(:send_status)

但我收到 400 错误的交货请求。有帮助吗?谢谢!

4

1 回答 1

2

避免将对象传递给delayed_job,而是使用ids:(您的delayed_job 进程可能会静默失败)

ReportMailer.delay.status_email(current_user.id, reports_ids, date)

在 status_email 中,拉出 current_user 并报告:

def status_email(userid, reports_ids, date)
  current_user = User.find_by_id(userid)
  reports = Report.find_all_by_id(reports_ids)
  ...
end
于 2014-02-06T23:18:33.380 回答