将另一个变量传递给rails3邮件接收方法

问题描述

我有一个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
看例子     

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...