PSCampbell
PSCampbell

Reputation: 868

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 => '[email protected]'


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. 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?

Upvotes: 0

Views: 53

Answers (1)

Sean Huber
Sean Huber

Reputation: 3985

Based on what you are explaining, you can just reuse the same mailer for all similar models.

class SendLink < ApplicationMailer
  default :from => '[email protected]'

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

Upvotes: 1

Related Questions