# Rookie with text editing

**URL:** <https://www.ruby-forum.com/t/rookie-with-text-editing/52535>\
**Category:** Rails\
**Created:** [January 16, 2006, 12:30am UTC](https://www.ruby-forum.com/t/rookie-with-text-editing/52535 "2006-01-16T00:30:25Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jpfeifer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/65b543/32.png) [@jpfeifer](https://www.ruby-forum.com/u/jpfeifer)\
**Post date:** [January 16, 2006, 12:30am UTC](https://www.ruby-forum.com/t/rookie-with-text-editing/52535/1 "2006-01-16T00:30:25Z")

</div>

Greetings,

This might be a pretty basic question not even totally rails specific,  
but how do I control text editing using ruby on rails?

For instance, I am using the ruby forum  
[http://www.ruby-forum.com/topic/new](http://www.ruby-forum.com/topic/new) as I type this and am typing into a  
textarea tag. I have this in my rails app and I want to know how to  
save the formatting - such as when I hit returns to go to a new line  
when I write.

When I do it with the rails site I am working on, it ignores the returns  
etc. and jumbles it all together.

Thanks,

Jason

---

<div class="post-metadata">

**Author:** ![jpfeifer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/65b543/32.png) [@jpfeifer](https://www.ruby-forum.com/u/jpfeifer)\
**Post date:** [January 16, 2006, 1:36am UTC](https://www.ruby-forum.com/t/rookie-with-text-editing/52535/2 "2006-01-16T01:36:34Z")

</div>

Just for debugging, output the text you are getting within a set of

```

```
 tags. Web browsers are designed to ignore whitespace, and

only follow formatting specified to them in markup rules.

For a VERY simple way of at least getting the spacing right, either on  
save or when display the string, replace all instances of ‘\n’ with  
‘  
’.

Example (in your view):  
\<%= @myObj.text\_area\_value.tr ‘\n’, ‘  
’ %\>

-Will

---

<div class="post-metadata">

**Author:** ![jpfeifer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/65b543/32.png) [@jpfeifer](https://www.ruby-forum.com/u/jpfeifer)\
**Post date:** [January 18, 2006, 3:50pm UTC](https://www.ruby-forum.com/t/rookie-with-text-editing/52535/3 "2006-01-18T15:50:11Z")

</div>

Jason

When people enter text in a text area, they expect the result to look  
like what they entered with proper line breaks, and indentations.

Problem:

- With plain text display + gsub(/\n/,‘  
’), you loose the  
indentation, but the line is correctly wrapped if it’s too long.
- With 
```
, line breaks and indentations work fine, but there is no
wrapping (1 paragraph → 1 very long flat line).
(I think CSS3 will bring wrapping to
```
)
```
```

The simplest solution I’ve found is an HTML editor.

TinyMCE  
[http://tinymce.moxiecode.com/](http://tinymce.moxiecode.com/)

In a snap - 1 line - you tell it to HTML-empower all your textAreas, or  
only the one with a given class, and voilÃ .  
Note: I started using it yesterday so I can’t tell you much about its  
limitations yet.

Alain
