Forum: Ruby on Rails How to keep formatting of text in textarea?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Szymon N. (Guest)
on 2006-03-09 13:59
Hi!

I've got a form for creating news and i'd like to keep formatting of the
text in the textarea - if user presses enter twice, or presses space ten
times it should be visible when editing or showing the news.

Probably i should add before_save filter and some regexps for adding
html tags, but i know almost nothing about regexp. Maybe there's a
simpler way also.
Łukasz Piestrzeniewicz (Guest)
on 2006-03-09 14:28
(Received via mailing list)
On 09/03/06, szymek <removed_email_address@domain.invalid> wrote:
> I've got a form for creating news and i'd like to keep formatting of the
> text in the textarea - if user presses enter twice, or presses space ten
> times it should be visible when editing or showing the news.
>
> Probably i should add before_save filter and some regexps for adding
> html tags, but i know almost nothing about regexp. Maybe there's a
> simpler way also.

Use RedCloth (http://whytheluckystiff.net/ruby/redcloth/) :)

Install RedCloth gem (preferably version 3.0.3 as 3.0.4 is somewhat
broken). Then when presenting contents of field use textilize() helper
like this:

<%= textilize(@item.description) %>
Szymon N. (Guest)
on 2006-03-09 14:57
Dzieki!!!

Is there already function for everything? :)
This topic is locked and can not be replied to.