我在报告控制器中有这个方法:
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
发送此状态时我无法发出任何请求,因此我使用delayed_job,替换
ReportMailer.status_email(current_user,reports,date).deliver with ReportMailer.status_email(current_user,reports,date).send_later(:send_status)
但我在送货上收到了400个不良请求。有什么帮助吗?谢谢!
答案 0 :(得分:2)
避免将对象传递给delayed_job并改为使用id :(您的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