E
E
Evgeny Strashko2015-10-14 14:50:25
Ruby on Rails
Evgeny Strashko, 2015-10-14 14:50:25

How to display data from a variable in the subject and body of the letter?

It is necessary to display data from a variable in a certain place in the text of the letter. The texts of the letters are stored in the database. Added @tmp variable in Mailer controller. In the text of the letter I add <%= @tmp %>, but it doesn't work, it displays - <%= @tmp %>. Tried #{@tmp}, same result.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
Z
Zaporozhchenko Oleg, 2015-10-14
@jonny_don

Where a letter template from the database is substituted into the body of the letter, you need to use the ERB processor, while passing the current context (binding) into it

@tmp = 'Some value'
email_body = ERB.new(mail_template_from_database).result(binding)

mail(to: user_email,  body: email_body,   content_type: "text/html",   subject: "Email subject")

M
malroc, 2015-10-14
@malroc

If the template engine is ERB, then the syntax is correct <%= @tmp %>(they forgot the % before the closing bracket).

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question