Rails/HAML: Line breaks in text mail

PlankTon picture PlankTon · May 16, 2011 · Viewed 9.4k times · Source

I'm just trying to format a haml-generated (text) mailer template, and I'm having a little difficulty getting it to read multiple line breaks. Eg: I'd have thought

Dear
= @user.name,

Your username is
= @user.username




Your status is
= @user.status

I had assumed that the multiple line breaks would be read, but the "Your status is" line comes out on the line directly beneath the username. (Yes, that many line breaks is an exaggeration of how many I want, but still)

So, the question is: Line breaks in haml text messages....erm, how?

Answer

Ivan picture Ivan · Nov 18, 2011

You can also use \ or ==:

Dear
= @user.name,
\
Your username is
= @user.username
\
\
\
\
Your status is
= @user.status

This has the added advantage of allowing you to use interpolation, whereas using the :plain filter won't.