# Preserving the format of text field data

**URL:** <https://www.ruby-forum.com/t/preserving-the-format-of-text-field-data/125701>\
**Category:** Rails\
**Created:** [January 11, 2008, 9:50am UTC](https://www.ruby-forum.com/t/preserving-the-format-of-text-field-data/125701 "2008-01-11T09:50:52Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Neon](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/f19dbf/32.png) [@Neon](https://www.ruby-forum.com/u/Neon)\
**Post date:** [January 11, 2008, 9:50am UTC](https://www.ruby-forum.com/t/preserving-the-format-of-text-field-data/125701/1 "2008-01-11T09:50:52Z")

</div>

Hello all,

I’m still fairly new to RoR. Had a question related to a form’s text  
field data. Given a blog model for example, with fields: title, date  
and body. If I were to type a full body’s worth of text with line  
breaks and such, much like I am doing now within this message field of  
the post. How would I be able to preserve the original typed in  
format without resorting to the use of the

```
html element within
the view template or having to input data in the field using

and  
  
 html elements?

I tried to glean off any information from the “Blog in 15 mins”  
railscast @ [rubyonrails.org](http://rubyonrails.org), but David only posted one sentence data  
in each body field. So nothing much to go on there.

-Neon
```

---

<div class="post-metadata">

**Author:** ![Neon](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/f19dbf/32.png) [@Neon](https://www.ruby-forum.com/u/Neon)\
**Post date:** [January 11, 2008, 6:27pm UTC](https://www.ruby-forum.com/t/preserving-the-format-of-text-field-data/125701/2 "2008-01-11T18:27:41Z")

</div>

Rails is preserving all the line breaks and so forth when the text is  
written to the database. But when you display this text on a web page,  
is in interpreted as HTML, which collapses multiple spaces to one, and  
ignores line breaks.

Somehow you need to get HTML tags marking up your text. My preferred  
way to do this is to use Textile markup for the text, and then Textile  
will create the HTML markup for you.

Here’s an article that explains how to use Textile:

[http://www.buildingwebapps.com/articles/6-easy-text-formatting-with-textile](http://www.buildingwebapps.com/articles/6-easy-text-formatting-with-textile)

Michael S.  
[www.BuildingWebApps.com](http://www.BuildingWebApps.com)  
[www.LearningRails.com](http://www.LearningRails.com)
