新手问题 关于用 resque 发邮件

sanvi · 2012年11月08日 · 最后由 sanivbyfish 回复于 2012年11月09日 · 1882 次阅读

同步发可以,异步发报错

user_mailer.rb
  def remind(notification,mail,subject)
    @notification = notification
      mail(:to => mail, :subject => subject )
  end

异步的话@notification是 nil

说明你的用法不对,为什么不传入一个 Notification 的 id?resque 在序列化反序列化的时候,不支持复杂的 AR 对象的,试试看这样:

@notification = Notification.find notification_id

传 id,不要传对象

Oh, by the way. Don't forget that your async mailer jobs will be processed by a separate worker. This means that you should resist the temptation to pass database-backed objects as parameters in your mailer and instead pass record identifiers. Then, in your delivery method, you can look up the record from the id and use it as needed.

#1 楼 @lgn21st #2 楼 @leomayleomay

好郁闷,不支持对象,我只好全部拆出来。。。

需要 登录 后方可回复, 如果你还没有账号请 注册新账号