Forum: Ruby on Rails Text_area + render text issues

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.
Sudhi K. (Guest)
on 2009-05-18 10:11

I am having problems with text area and render :text and RJS used to
fill text area content.

I have a simple readonly text area in which I want to

1. I use a periodic_update method to call update_status method every 5
seconds which is supposed to update the contents of text area.
2. Add text that the controller function returns - This could have \r\n
and that should be shown as line break in text area.
3. I should be able to update the content and not use replace_html from
RJS since the content I want to display is xml.

Issue 1: The text area does not retain \r\n how do I force it to retain.
Issue 2: In RJS page('text_area') << "RAW javascript" can retain '\r\n'
but can't use a parameter sent into the RJS in "RAW Javascript" area.
Issue 3: page['text_area'].value = @text retains line breaks but this
does not allow for updates in a text_area this can only replace content.

Thanks for the help...

George H. (Guest)
on 2010-11-09 18:31
I had a similar problem.   I expect users to enter html or xml in my
text area and I also wanted to retain line breaks when rendering a page.
The solution was quite simple

The html <pre> tag retained the line breaks and html_escape allowed me
to render the html.  This  is probably a rather large security hole but
I'm working on an internally facing application so it's okay.   The user
can now enter whatever they want in the textarea and it's rendered
correctly when I display the data on another page.

When I render the text, it now looks like...

There should be a line break
This topic is locked and can not be replied to.