# Convert \\n newlines to html \<br\>

**URL:** <https://www.ruby-forum.com/t/convert-n-newlines-to-html-br/77541>\
**Category:** Rails\
**Created:** [March 7, 2006, 12:48am UTC](https://www.ruby-forum.com/t/convert-n-newlines-to-html-br/77541 "2006-03-07T00:48:44Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![charleyramm](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/439d5e/32.png) [@charleyramm](https://www.ruby-forum.com/u/charleyramm)\
**Post date:** [March 7, 2006, 12:48am UTC](https://www.ruby-forum.com/t/convert-n-newlines-to-html-br/77541/1 "2006-03-07T00:48:44Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![charleyramm](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/439d5e/32.png) [@charleyramm](https://www.ruby-forum.com/u/charleyramm)\
**Post date:** [March 7, 2006, 3:14am UTC](https://www.ruby-forum.com/t/convert-n-newlines-to-html-br/77541/2 "2006-03-07T03:14:43Z")

</div>

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

-Nb

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

```

---

<div class="post-metadata">

**Author:** ![charleyramm](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/439d5e/32.png) [@charleyramm](https://www.ruby-forum.com/u/charleyramm)\
**Post date:** [March 8, 2006, 1:55am UTC](https://www.ruby-forum.com/t/convert-n-newlines-to-html-br/77541/3 "2006-03-08T01:55:28Z")

</div>

Or use RedCloth:

gem install redcloth

textilize(address)

You can do as much formatting as you like.

[http://whytheluckystiff.net/ruby/redcloth/](http://whytheluckystiff.net/ruby/redcloth/)

-Jonny.
