Rails:在event_mailer中初始化全局变量

时间:2012-11-25 00:25:14

标签: ruby-on-rails sendmail

在我的mailers / event_mailer类中,我有几个方法。每种方法都是:

  1. 接收用户哈希输入
  2. 将用户哈希变为全局变量
  3. 从event_mailers调用相应的.html.erb文件以发送电子邮件
  4. 而不是重复步骤1& 2对于每个方法,有没有办法在event_mailer类的“构造函数”中初始化一次?

    澄清代码:

    注册控制器代码:

              EventMailer.notify_admins(@user,subject,topic).deliver
    

    event_mailer.rb代码:

    class EventMailer < ActionMailer::Base
      @@smtp_settings = {
      ..........
      }
    
    def notify_admins(user,subject,topic)
        @user = user
        @topic = topic
        ......
        mail(:from => 'test@example.com', :to => 'someone@someone.com', :subject => subject)
    end
    
    def notify_accounts(user,subject,topic)
        @user = user
        @topic = topic
        ......
        mail(:from => 'test@example.com', :to => 'someone@someone.com', :subject => subject)
    end
    

0 个答案:

没有答案
相关问题