Reputation: 2393
I would like send email with html.erb template and I have some code. Like this:
class Mailer < ActionMailer::Base
def notification(to_email)
begin
mail(to: '[email protected]', subject: "Test message")
rescue Exception => e
return
end
end
end
And some html.erb file:
Hello, <%= @name %>.
But I don't know how to attach this template for my method. Help me please with this issue, because i can't fount normally manual about it.
Upvotes: 0
Views: 510
Reputation: 4156
You can create a page named notification.html.erb
in app/views/mailer
directory. You will get all instance variable in notification.html.erb
that is defined in your def notification(to_email)
def notification(to_email)
@name = #pass name here
#your code goes here
end
Now @name
will be available in notification.html.erb
like
Hello, <%= @name %>
Upvotes: 2