Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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" =>

Hello

Hello

(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.

like image 914
Matteo Melani Avatar asked Aug 30 '11 04:08

Matteo Melani


2 Answers

I know I'm a little late, but I actually think the proper solution to this, at least within Rails, is to leverage the simple_format helper method provided from ActionView::Helpers::TextHelper.

like image 193
Batkins Avatar answered Sep 30 '22 09:09

Batkins


Wrap your text in a Pre tag:

<%= content_tag('pre', "Hello\n\nHello") %>
like image 23
jdeseno Avatar answered Sep 30 '22 11:09

jdeseno