How to remove loads of white space / new lines from the text body of an email from rails 3 mail?

I have an email in which I show text_body to my users in my rails 3 application.

The problem is that text_body comes with lots of spaces between the lines / paragraphs and when I display it with simple_format to display the formatted text in which it is loaded.

Does anyone know how to remove this to make email look like it should be properly formatted on a page in a browser?

thanks a lot rick

+3
source share
3 answers

It's pretty fast

text.squeeze(" \t")

It leaves no more than one adjacent space and / or tab anywhere in the text.

+1

- :

text.strip.gsub(/\s*\n\s*/, "\n")

+1

Assuming you're using ERB to create email, keep in mind that <%%> will add a new line in the output. If you want to avoid this new line, use <% -%> instead. (Do not say that this is your problem, but you can look into it.)

0
source

All Articles