Forum: Ruby on Rails Formatting input/output of a text box

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.
Dave H. (Guest)
on 2006-01-23 01:50
(Received via mailing list)

What's the best way to handle formating of a text_area? I have a
in my rails app where people can leave comments and I'd like to
automatically convert the line breaks into <br /> tags, or just simply
a whole paragraph in <p></p> tags. I'm currently doing the following in
comments controller to insert line breaks when the user presses <ENTER>
within the text_area, however I know there has to be a better way.

comment_body = @comment.body
comment_body.gsub!( /(.*)(\n)/, '\1<br />' )
@comment.body = comment_body

Dave H.
Gerard P. (Guest)
on 2006-01-23 01:59
(Received via mailing list)

This one works for output and goes straight in the view:

<%= todo.description.gsub "\n",'<br />' %>

With this in a list action:

def list_todos

	# lot of parms not necesarry ofcourse
	@todo_pages, @todos = paginate(:todos, options={:per_page => 10, :order
'prio DESC'})



On Monday 23 January 2006 00:49, Dave H. tried to type something
> comment_body.gsub!( /(.*)(\n)/, '\1<br />' )
> @comment.body = comment_body
> Thanks!
> Dave H.

"Who cares if it doesn't do anything?  It was made with our new
Triple-Iso-Bifurcated-Krypton-Gate-MOS process ..."

My $Grtz =~ Gerard;
Bob S. (Guest)
on 2006-01-23 02:50
(Received via mailing list)
I think you would be better off to leave the raw data (maybe you want to
email the comment some day??) alone and only translate the line feeds to
br's in your views when presenting the data. Use Gerards response to do

Bob S.
Dave H. (Guest)
on 2006-01-23 02:56
(Received via mailing list)
That's a good idea. I never thought about that. I think I will leave it
it's raw form and use Gerard's way.

Thanks Bob,
This topic is locked and can not be replied to.