在我的 mailers/event_mailer 类中,我有一些方法。这些方法中的每一个:
- 接收用户散列输入
- 将用户哈希转换为全局变量
- 从 event_mailers 调用相应的 .html.erb 文件来发送电子邮件
有没有办法在 event_mailer 类的“构造函数”中初始化一次,而不是为每个方法重复步骤 1 和 2?
澄清代码:
注册控制器代码:
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