Hello, What''s the best way to handle formating of a text_area? I have a text_area 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 wrap a whole paragraph in <p></p> tags. I''m currently doing the following in my 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 Thanks! Dave Hoefler -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060122/d5b401ae/attachment-0001.html
Dave, 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 @todos # lot of parms not necesarry ofcourse @todo_pages, @todos = paginate(:todos, options={:per_page => 10, :order => ''prio DESC''}) end Regards, Gerard. On Monday 23 January 2006 00:49, Dave Hoefler tried to type something like:> Hello, > > What''s the best way to handle formating of a text_area? I have a text_area > 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 wrap > a whole paragraph in <p></p> tags. I''m currently doing the following in my > 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 > > Thanks! > Dave Hoefler-- "Who cares if it doesn''t do anything? It was made with our new Triple-Iso-Bifurcated-Krypton-Gate-MOS process ..." My $Grtz =~ Gerard; ~ :wq!
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 that. Bob Silva> -----Original Message----- > From: rails-bounces@lists.rubyonrails.org [mailto:rails- > bounces@lists.rubyonrails.org] On Behalf Of Gerard Petersen > Sent: Sunday, January 22, 2006 3:59 PM > To: rails@lists.rubyonrails.org > Subject: Re: [Rails] Formatting input/output of a text box > > Dave, > > 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 > @todos > > # lot of parms not necesarry ofcourse > @todo_pages, @todos = paginate(:todos, options={:per_page => 10, > :order => > ''prio DESC''}) > end > > > Regards, > > Gerard. > > > On Monday 23 January 2006 00:49, Dave Hoefler tried to type something > like: > > Hello, > > > > What''s the best way to handle formating of a text_area? I have a > text_area > > 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 > wrap > > a whole paragraph in <p></p> tags. I''m currently doing the following in > my > > 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 > > > > Thanks! > > Dave Hoefler > > -- > "Who cares if it doesn''t do anything? It was made with our new > Triple-Iso-Bifurcated-Krypton-Gate-MOS process ..." > > My $Grtz =~ Gerard; > ~ > :wq! > > > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails
That''s a good idea. I never thought about that. I think I will leave it in it''s raw form and use Gerard''s way. Thanks Bob, Dave On 1/22/06, Bob Silva <me@bobsilva.com> wrote:> > 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 > that. > > Bob Silva > > > -----Original Message----- > > From: rails-bounces@lists.rubyonrails.org [mailto:rails- > > bounces@lists.rubyonrails.org] On Behalf Of Gerard Petersen > > Sent: Sunday, January 22, 2006 3:59 PM > > To: rails@lists.rubyonrails.org > > Subject: Re: [Rails] Formatting input/output of a text box > > > > Dave, > > > > 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 > > @todos > > > > # lot of parms not necesarry ofcourse > > @todo_pages, @todos = paginate(:todos, options={:per_page => 10, > > :order => > > ''prio DESC''}) > > end > > > > > > Regards, > > > > Gerard. > > > > > > On Monday 23 January 2006 00:49, Dave Hoefler tried to type something > > like: > > > Hello, > > > > > > What''s the best way to handle formating of a text_area? I have a > > text_area > > > 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 > > wrap > > > a whole paragraph in <p></p> tags. I''m currently doing the following > in > > my > > > 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 > > > > > > Thanks! > > > Dave Hoefler > > > > -- > > "Who cares if it doesn''t do anything? It was made with our new > > Triple-Iso-Bifurcated-Krypton-Gate-MOS process ..." > > > > My $Grtz =~ Gerard; > > ~ > > :wq! > > > > > > > > _______________________________________________ > > Rails mailing list > > Rails@lists.rubyonrails.org > > http://lists.rubyonrails.org/mailman/listinfo/rails > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060123/23a32ebd/attachment.html