我有一个mail_receiver,它通过pop拉入我的电子邮件,然后将该消息传递给我的DropBoxMailer,如下所示:
DropBoxMailer.receive(email.pop)
我需要将一个变量传递到DropBoxMailer类,因此需要执行类似的操作
DropBoxMailer.receive(email.pop, another_var)
有人知道如何正确地做到这一点吗?
因为receive只需要1而不是2个参数?
谢谢Rick
您可以这样做:
class DropBoxMailer < ActionMailer::Base
# redefine ActionMailer.receive with an additional parameter
def self.receive(raw_mail, email_account, another_var)
ActiveSupport::Notifications.instrument("receive.action_mailer") do |payload|
mail = Mail.new(raw_mail)
set_payload_for_mail(payload, mail)
new.receive(mail, another_var)
end
end
def receive(mail, another_var)
..
end
end
参见示例