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

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and 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
Nshbrown N. (Guest)
on 2006-03-07 04:14
(Received via mailing list)
<%= address.gsub(/\n/, '<br />') %>


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

gem install redcloth


You can do as much formatting as you like.

This topic is locked and can not be replied to.