# MySQL Text field: breaks/paragraphs missing in view

**URL:** <https://www.ruby-forum.com/t/mysql-text-field-breaks-paragraphs-missing-in-view/145085>\
**Category:** Rails\
**Created:** [August 5, 2008, 9:19pm UTC](https://www.ruby-forum.com/t/mysql-text-field-breaks-paragraphs-missing-in-view/145085 "2008-08-05T21:19:39Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Leerlaufprozess](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/ccd318/32.png) [@Leerlaufprozess](https://www.ruby-forum.com/u/Leerlaufprozess)\
**Post date:** [August 5, 2008, 9:19pm UTC](https://www.ruby-forum.com/t/mysql-text-field-breaks-paragraphs-missing-in-view/145085/1 "2008-08-05T21:19:39Z")

</div>

Hi everyone,

I’m currently trying to learn rails and I’m writing my first test  
application. I’ve got a MySQL Database with the field “the\_quote” (the  
field type is “text”) and I’ve inserted some values via scaffold. The  
text field contains breaks that are being displayed properly in MySQL  
but when I use \<%= table.the\_quote %\> in the view the breaks don’t  
show up.

---

<div class="post-metadata">

**Author:** ![Leerlaufprozess](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/ccd318/32.png) [@Leerlaufprozess](https://www.ruby-forum.com/u/Leerlaufprozess)\
**Post date:** [August 5, 2008, 9:24pm UTC](https://www.ruby-forum.com/t/mysql-text-field-breaks-paragraphs-missing-in-view/145085/2 "2008-08-05T21:24:56Z")

</div>

On 5 Aug 2008, at 20:16, Leerlaufprozess wrote:

> Hi everyone,
> 
> I’m currently trying to learn rails and I’m writing my first test  
> application. I’ve got a MySQL Database with the field “the\_quote” (the  
> field type is “text”) and I’ve inserted some values via scaffold. The  
> text field contains breaks that are being displayed properly in MySQL  
> but when I use \<%= table.the\_quote %\> in the view the breaks don’t  
> show up.

This isn’t really a rails or a mysql issue. HTML dictates that all  
white space is basically the same as a single space, so line returns  
are ignored and multiple spaces between 2 words accomplish nothing.  
You need to translate the line returns into markup. The simple\_format  
helper does this.

Fred

---

<div class="post-metadata">

**Author:** ![Leerlaufprozess](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/ccd318/32.png) [@Leerlaufprozess](https://www.ruby-forum.com/u/Leerlaufprozess)\
**Post date:** [August 5, 2008, 9:27pm UTC](https://www.ruby-forum.com/t/mysql-text-field-breaks-paragraphs-missing-in-view/145085/3 "2008-08-05T21:27:41Z")

</div>

Leerlaufprozess wrote:

> Hi everyone,
> 
> I’m currently trying to learn rails and I’m writing my first test  
> application. I’ve got a MySQL Database with the field “the\_quote” (the  
> field type is “text”) and I’ve inserted some values via scaffold. The  
> text field contains breaks that are being displayed properly in MySQL  
> but when I use \<%= table.the\_quote %\> in the view the breaks don’t  
> show up.

Hi,

Line breaks don’t show when rendered in HTML on a browser. If you add  
  
 at the end of each line, it will render a break when viewed in a  
web browser, otherwise HTML ignores whitespace so if you have extra  
spaces they will just show as one space. I hope that makes sense.

---

<div class="post-metadata">

**Author:** ![Leerlaufprozess](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/ccd318/32.png) [@Leerlaufprozess](https://www.ruby-forum.com/u/Leerlaufprozess)\
**Post date:** [August 5, 2008, 9:32pm UTC](https://www.ruby-forum.com/t/mysql-text-field-breaks-paragraphs-missing-in-view/145085/4 "2008-08-05T21:32:34Z")

</div>

Wow, thanks! I’m using \<%= simple\_format(table.the\_quote) %\> and it  
works perfectly!

---

<div class="post-metadata">

**Author:** ![Leerlaufprozess](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/ccd318/32.png) [@Leerlaufprozess](https://www.ruby-forum.com/u/Leerlaufprozess)\
**Post date:** [August 5, 2008, 9:45pm UTC](https://www.ruby-forum.com/t/mysql-text-field-breaks-paragraphs-missing-in-view/145085/5 "2008-08-05T21:45:29Z")

</div>

On 5 Aug 2008, at 20:31, Leerlaufprozess wrote:

> Wow, thanks! I’m using \<%= simple\_format(table.the\_quote) %\> and it  
> works perfectly!

Don’t forget to pass the text through h first (eg  
simple\_format(h(table.the\_quote))) or users can inject bad things into  
your page.

Fred
