问题描述
我有一个mail_receiver,它通过pop提取我的电子邮件,然后将该消息传递给我的DropBoxMailer,如下所示:
DropBoxMailer.receive(email.pop)
我需要将变量传递给DropBoxMailer类,因此需要执行以下操作
DropBoxMailer.receive(email.pop,another_var)
有人知道如何正确执行此操作吗?
因为只期望1个参数而不是2个参数?
谢谢
里克
解决方法
您可以这样:
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
看例子