新手问题 关于用 resque 发邮件

sanvi · November 08, 2012 · Last by sanivbyfish replied at November 09, 2012 · 1882 hits

同步发可以,异步发报错

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

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

You need to Sign in before reply, if you don't have an account, please Sign up first.