Matteo Melani Matteo Melani - 4 months ago 8
Ruby Question

converting plain text to html

My rails 3 app receives emails. Some of them are plain text. When the app displays them to the user I want them to be properly formatted. In other word I want to encode plain text into html. For example: "Hello\n\nHello" => HelloHello (or something like it).

Of course I can write my own 4 lines of code but I am sure those 4 lines have already be written, tested and wrapped in some nice method call.

Answer

Wrap your text in a Pre tag:

<%= content_tag('pre', "Hello\n\nHello") %>
Comments