简体   繁体   English

Mailer中的Rails模型变量

[英]Rails Model Variables in Mailer

I'm not one hundred percent sure I can explain what I'm hoping to do, but here's an attempt: 我不确定百分百可以解释自己的意愿,但这是一种尝试:

I've got several models that I need to build mailers for. 我有一些需要构建邮件程序的模型。 Here's one: 这是一个:

 class SendLink < ApplicationMailer
  default :from => 'info@mysite.com'


def email(order)
    @order = order
     mail(
  :subject => 'Critical Documentation Needed' ,
  :to  => @order.recipient ,
  :track_opens => 'true'
)
  end
 end

In addition to the order model shown above, I've got several other models that I need mailers for, all with pretty much exactly the same content. 除了上面显示的order模型外,我还有一些其他需要邮件服务的模型,它们的内容几乎完全相同。 So, ideally, I would like to reuse the mailer and template over and over for each model and have the model be a variable. 因此,理想情况下,我想为每个模型反复使用邮件程序和模板,并将模型作为变量。

Is it possible to make the model a variable in the mailer, and if so, what sort of syntax would one use? 是否可以在邮件程序中使模型成为变量,如果可以,将使用哪种语法?

Based on what you are explaining, you can just reuse the same mailer for all similar models. 根据您的解释,您可以将所有相同模型的邮件重复使用。

class SendLink < ApplicationMailer
  default :from => 'info@mysite.com'

  def email( object )
    @object = object
    mail(
      :subject => 'Critical Documentation Needed' ,
      :to  => @object.recipient ,
      :track_opens => 'true'
    )
  end
end

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM