Ronartos
2008-Feb-18 01:32 UTC
Formatting a Text or CharVar(255) data type with Carriage Return or [enter]
Is there a way to format a Text or CharVar data field to include the carriage return or [ENTER] ?? Example i saved a data as follows: This is Line 1 Line 2 Line 3 Can I be able to display them again like that? coz right now I a wish to display them again it''ll be shown like this: This is Line 1 Line 2 Line 3 --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Phillip Koebbe
2008-Feb-18 12:16 UTC
Re: Formatting a Text or CharVar(255) data type with Carriage Return or [enter]
On Feb 17, 2008, at 7:32 PM, Ronartos wrote:> > Is there a way to format a Text or CharVar data field to include the > carriage return or [ENTER] ?? > > > Example i saved a data as follows: > > This is Line 1 > Line 2 > Line 3 > > Can I be able to display them again like that? coz right now I a wish > to display them again it''ll be shown like this: > > This is Line 1 Line 2 Line 3 >If you are outputting as HTML, you''d have to replace carriage return/ line feed with a <br /> tag. There''s probably a nice railsy way to do it, but I wrote myself a little helper function that does it using gsub! . On the other hand, if you are capturing the data in a textarea and output it to a textarea, you shouldn''t have to do anything. DISCLAIMER: I haven''t been up very long this morning, so I might not be thinking clearly. Peace, Phillip --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Ryan Bigg (Radar)
2008-Feb-18 12:22 UTC
Re: Formatting a Text or CharVar(255) data type with Carriage Return or [enter]
string.gsub("\n","<br />") On Feb 18, 2008 10:46 PM, Phillip Koebbe <phillipkoebbe-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > On Feb 17, 2008, at 7:32 PM, Ronartos wrote: > > > > > Is there a way to format a Text or CharVar data field to include the > > carriage return or [ENTER] ?? > > > > > > Example i saved a data as follows: > > > > This is Line 1 > > Line 2 > > Line 3 > > > > Can I be able to display them again like that? coz right now I a wish > > to display them again it''ll be shown like this: > > > > This is Line 1 Line 2 Line 3 > > > > If you are outputting as HTML, you''d have to replace carriage return/ > line feed with a <br /> tag. There''s probably a nice railsy way to > do it, but I wrote myself a little helper function that does it using > gsub! . > > On the other hand, if you are capturing the data in a textarea and > output it to a textarea, you shouldn''t have to do anything. > > DISCLAIMER: I haven''t been up very long this morning, so I might not > be thinking clearly. > > Peace, > Phillip > > > > >-- Ryan Bigg http://www.frozenplague.net Feel free to add me to MSN and/or GTalk as this email. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Peter De Berdt
2008-Feb-18 12:26 UTC
Re: Formatting a Text or CharVar(255) data type with Carriage Return or [enter]
On 18 Feb 2008, at 13:16, Phillip Koebbe wrote:>> This is Line 1 >> Line 2 >> Line 3 >> >> Can I be able to display them again like that? coz right now I a wish >> to display them again it''ll be shown like this: >> >> This is Line 1 Line 2 Line 3 >> > > If you are outputting as HTML, you''d have to replace carriage return/ > line feed with a <br /> tag. There''s probably a nice railsy way to > do it, but I wrote myself a little helper function that does it using > gsub! . > > On the other hand, if you are capturing the data in a textarea and > output it to a textarea, you shouldn''t have to do anything. > > DISCLAIMER: I haven''t been up very long this morning, so I might not > be thinking clearly.http://api.rubyonrails.com/classes/ActionView/Helpers/TextHelper.html simple_format(text) Returns text transformed into HTML using simple formatting rules. Two or more consecutive newlines(\n\n) are considered as a paragraph and wrapped in <p> tags. One newline (\n) is considered as a linebreak and a <br /> tag is appended. This method does not remove the newlines from the text. Examples my_text = """Here is some basic text... ...with a line break.""" simple_format(my_text) # => "<p>Here is some basic text...<br />...with a line break.</p>" more_text = """We want to put a paragraph... ...right there.""" simple_format(more_text) # => "<p>We want to put a paragraph...</p><p>...right there.</p>" --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Ryan Bigg (Radar)
2008-Feb-18 12:52 UTC
Re: Formatting a Text or CharVar(255) data type with Carriage Return or [enter]
simple_format seems to put paragraphs where I don''t want paragraphs sometimes. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---