This is more of a ruby question, but I have a textarea in a form, and
for later presentation I need to convert the line endings to <br>.
The value from the form is, for example "line of text\r\nmore text".
I tried gsub(''\r\n'', "<br>"), but it
doesn''t find the \r\n. How do I
specify those characters?
Thanks,
-George
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
On 8/29/07, George Bailey <listcatcher-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > This is more of a ruby question, but I have a textarea in a form, and > for later presentation I need to convert the line endings to <br>. > > The value from the form is, for example "line of text\r\nmore text". > I tried gsub(''\r\n'', "<br>"), but it doesn''t find the \r\n. How do I > specify those characters?You would need to use double quotes around \r\n, "\r\n", or express it as a regex, /\r\n/. But see also the built-in simple_format helper. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
George Bailey wrote:> The value from the form is, for example "line of text\r\nmore text". > I tried gsub(''\r\n'', "<br>"), but it doesn''t find the \r\n. How do I > specify those characters?gsub("\r\n", "<br>") Double-quote the \r\n. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Aug 29, 2007, at 1:29 PM, Daniel Waite wrote:> gsub("\r\n", "<br>") > > Double-quote the \r\n.That was it. Thanks! -George --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Occasionally it will be \n, and not \r\n.
text.gsub("\n",<br />)
On Aug 30, 8:31 am, George Bailey
<listcatc...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:> On Aug 29, 2007, at 1:29 PM, Daniel Waite wrote:
>
> > gsub("\r\n", "<br>")
>
> > Double-quote the \r\n.
>
> That was it. Thanks!
>
> -George
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
On Aug 29, 2007, at 5:32 PM, Ryan Bigg wrote:> Occasionally it will be \n, and not \r\n. > > text.gsub("\n",<br />)Thanks. I added that after the \r\n line. I figured one of them has to work. But then I tried out the simple_format that Bob Showalter suggested, which seems to be a better way to do it. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
use this http://webonrails.com/2006/08/07/converting-all-newline-characters-to-br-tag/ On Aug 29, 9:30 pm, George Bailey <listcatc...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> This is more of a ruby question, but I have a textarea in a form, and > for later presentation I need to convert the line endings to <br>. > > The value from the form is, for example "line of text\r\nmore text". > I tried gsub(''\r\n'', "<br>"), but it doesn''t find the \r\n. How do I > specify those characters? > > Thanks, > -George--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
rails has its own simple_format function, it may meet your need. simple_format(text) Returns text transformed into HTML using very simple formatting rules Surrounds paragraphs with <p> tags, and converts line breaks into <br /> Two consecutive newlines(\n\n) are considered as a paragraph, one newline (\n) is considered a linebreak, three or more consecutive newlines are turned into two newlines On Aug 29, 12:30 pm, George Bailey <listcatc...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> This is more of a ruby question, but I have a textarea in a form, and > for later presentation I need to convert the line endings to <br>. > > The value from the form is, for example "line of text\r\nmore text". > I tried gsub(''\r\n'', "<br>"), but it doesn''t find the \r\n. How do I > specify those characters? > > Thanks, > -George--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---