jeudi 28 mai 2015

pass instance variable while using observer pattern in rails

I'm using observer pattern in rails. The "delivered_email" method in TestObserver will be called after notification email been sent out. How could I pass the instance variable in "notification" to the "delivered_email"? I could add it either in the header or subject. But it could pose security issue since user who received email could also see the variable. Is there any better way to solve it?

class GeneralMailer < ActionMailer::Base
  def notification(data)
    @emails = data[:emails]
    subject = "#{@sender.to_s}"
    mail(:to => @emails, :subject => subject)
  end
end

class TestObserver
  def self.delivered_email(message)
    begin
      # do something here
      puts @emails
    rescue => ex
      # do something here
    end
  end

ActionMailer::Base.register_observer(TestObserver)

Aucun commentaire:

Enregistrer un commentaire