Unlike most plain text email related questions, my problem is that there are too many line breaks in the plain text emails Rails is sending out.
For simplicity while starting up, I ditched HTML emails altogether and just use plain text emails (using .text.erb views). My problems occur where I have conditional lines in the view, as the new line of code in my view file carries over to the email.
For example:
Line 1
<%= "Line 2" if false %>
Line 3
will render as:
Line 1
Line 3
and not the intended output:
Line 1
Line 3
My current hack is to use the following:
Line 1
<%= "Line 2\n" if false %>Line 3
This can get really messy when there are multiple conditionals in a row.
Surely there must be a better way!
You must be using double quotes, and you use \r\n to make a new line.
Microsoft Outlook removes line breaks in signatures for messages sent in plain text format. For the sender, the message looks normal but when displayed to the recipient, line breaks are removed so the formatting of the signature is compromised.
To do a line break in HTML, use the <br> tag.
This is to answer Felix' question on Andy Waite's answer (I don't think multi-line code is possible in comments and this question is about multi-line code).
I think <%= "foo\n" if something -%>
would work, but this seems cleaner to me:
Line 1
<% if something -%>
foo
<% end -%>
Line 3
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With