Forum: Ruby on Rails rookie with text editing

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.
E25296bf52723dc37bc462271eb02d2d?d=identicon&s=25 Jason Pfeifer (jpfeifer)
on 2006-01-16 00:30

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 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.


9b7647d55df4584d7031130915556040?d=identicon&s=25 Will Briggs (Guest)
on 2006-01-16 01:36
(Received via mailing list)
Just for debugging, output the text you are getting within a set of
<pre></pre> 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
'<br />'.

Example (in  your view):
<%= '\n', '<br />' %>

0091f92762685860109bbcb02edfdf27?d=identicon&s=25 Alain Ravet (Guest)
on 2006-01-18 15:50
(Received via mailing list)

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

- With plain text display + gsub(/\n/,'<br>'),  you loose the
indentation, but the line is correctly wrapped if it's too long.
- With <pre>, 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 <pre>)

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


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.

This topic is locked and can not be replied to.