Forum: Ruby on Rails Convert \n newlines to html <br>

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Charley R. (Guest)
on 2006-03-07 01:48
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
Nshbrown N. (Guest)
on 2006-03-07 04:14
(Received via mailing list)
<%= address.gsub(/\n/, '<br />') %>

-Nb

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 Nathaniel S. H. Brown                           http://nshb.net
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Jonathan V. (Guest)
on 2006-03-08 02:55
Or use RedCloth:

gem install redcloth

textilize(address)

You can do as much formatting as you like.

http://whytheluckystiff.net/ruby/redcloth/

-Jonny.
This topic is locked and can not be replied to.