Convert \n newlines to html <br>


#1

I have a textarea that accepts a shipping address, so I need to convert
newlines when it is displayed as html. I am new to ruby, and rails so an
example would be appreciated. I want to do this in the ‘display’, not
the stored text if possible, since I use the newlines when generating a
pdf.
Thanks.
charley


#2

<%= address.gsub(/\n/, ‘
’) %>

-Nb

 Nathaniel S. H. Brown                           http://nshb.net

#3

Or use RedCloth:

gem install redcloth

textilize(address)

You can do as much formatting as you like.

-Jonny.