Matthias
Matthias

Reputation: 1953

Rails: instance variable not coming through in ActionMailer

I have a mailer BetaInviteMailer with action beta_invite, taking arguments name and email as follows:

class BetaInviteMailer < ApplicationMailer
  def beta_invite(name, email)
    mail to: email, subject: 'Invitation to my closed bèta'
    @name = name
  end
end

The beta_invite.html.erb reads:

Dear <%= @name %>,
... 

When running BetaInviteMailer.beta_invite("John Doe", "[email protected]") in the console

The variable @name comes out 'nil'.

What am I doing wrong?

Upvotes: 0

Views: 45

Answers (1)

Sachin R
Sachin R

Reputation: 11876

class BetaInviteMailer < ApplicationMailer
  def beta_invite(name, email)
    @name = name
    mail to: email, subject: 'Invitation to my closed bèta'   
  end
end

define @variable before mail call

Upvotes: 1

Related Questions