Hi, how convert string to html (\n to <br />) ? I found only scape and unscapehtml in ruby reference and they don''t do this \n to <br /> I need to use replace ?? Thank you -- Pedro C. Valentini pedro-p14LI7ZcAE/pVLaUnt/cCQC/G2K4zDHf@public.gmane.org +55 (21) 8708-8035
It depends on what do you want to do. If you want to do some intellligent formatting for your strings, then check out redcloth http://www.whytheluckystiff.net/ruby/redcloth/ If you just want to output your string "as-is", why not put "<pre>" - tags around it. Heikki On 4/26/05, Pedro Valentini <pedro-p14LI7ZcAE/pVLaUnt/cCQC/G2K4zDHf@public.gmane.org> wrote:> Hi, > how convert string to html (\n to <br />) ? > I found only scape and unscapehtml in ruby reference and they don''t do > this \n to <br /> > I need to use replace ?? > > Thank you > > -- > > Pedro C. Valentini > pedro-p14LI7ZcAE/pVLaUnt/cCQC/G2K4zDHf@public.gmane.org > +55 (21) 8708-8035 > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-- // heikki tunkelo
Pedro Valentini wrote:> Hi, > how convert string to html (\n to <br />) ? > I found only scape and unscapehtml in ruby reference and they don''t do > this \n to <br /> > I need to use replace ??"try this\non for size".gsub("\n", ''<br />'') jeremy
It is not working... I think that it look for ''\n'' in the text and not a line break. Jeremy Kemper escreveu:>Pedro Valentini wrote: > > >>Hi, >>how convert string to html (\n to <br />) ? >>I found only scape and unscapehtml in ruby reference and they don''t do >>this \n to <br /> >>I need to use replace ?? >> >> > >"try this\non for size".gsub("\n", ''<br />'') > >jeremy >_______________________________________________ >Rails mailing list >Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org >http://lists.rubyonrails.org/mailman/listinfo/rails > > > > >-- Pedro C. Valentini pedro-p14LI7ZcAE/pVLaUnt/cCQC/G2K4zDHf@public.gmane.org +55 (21) 8708-8035
I want somethink simple. Receibe one text in a textfield and show this text in a html page. But textfield use \n to break lines and html pages <br> .gsub(''\n'',''<br />'') don''t work... What more can I try?? Thank you Heikki Tunkelo escreveu:>It depends on what do you want to do. > >If you want to do some intellligent formatting for your strings, then >check out redcloth http://www.whytheluckystiff.net/ruby/redcloth/ > >If you just want to output your string "as-is", why not put "<pre>" - >tags around it. > >Heikki > >On 4/26/05, Pedro Valentini <pedro-p14LI7ZcAE/pVLaUnt/cCQC/G2K4zDHf@public.gmane.org> wrote: > > >>Hi, >>how convert string to html (\n to <br />) ? >>I found only scape and unscapehtml in ruby reference and they don''t do >>this \n to <br /> >>I need to use replace ?? >> >>Thank you >> >>-- >> >>Pedro C. Valentini >>pedro-p14LI7ZcAE/pVLaUnt/cCQC/G2K4zDHf@public.gmane.org >>+55 (21) 8708-8035 >> >>_______________________________________________ >>Rails mailing list >>Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org >>http://lists.rubyonrails.org/mailman/listinfo/rails >> >> >> > > > >-- Pedro C. Valentini pedro-p14LI7ZcAE/pVLaUnt/cCQC/G2K4zDHf@public.gmane.org +55 (21) 8708-8035
I resolved the problem with html helper simple_format function... Thank you Pedro Valentini escreveu:> > I want somethink simple. > Receibe one text in a textfield and show this text in a html page. > But textfield use \n to break lines and html pages <br> > .gsub(''\n'',''<br />'') don''t work... > > What more can I try?? > > Thank you > > > Heikki Tunkelo escreveu: > >> It depends on what do you want to do. >> >> If you want to do some intellligent formatting for your strings, then >> check out redcloth http://www.whytheluckystiff.net/ruby/redcloth/ >> >> If you just want to output your string "as-is", why not put "<pre>" - >> tags around it. >> >> Heikki >> >> On 4/26/05, Pedro Valentini <pedro-p14LI7ZcAE/pVLaUnt/cCQC/G2K4zDHf@public.gmane.org> wrote: >> >> >>> Hi, >>> how convert string to html (\n to <br />) ? >>> I found only scape and unscapehtml in ruby reference and they don''t do >>> this \n to <br /> >>> I need to use replace ?? >>> >>> Thank you >>> >>> -- >>> >>> Pedro C. Valentini >>> pedro-p14LI7ZcAE/pVLaUnt/cCQC/G2K4zDHf@public.gmane.org >>> +55 (21) 8708-8035 >>> >>> _______________________________________________ >>> Rails mailing list >>> Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org >>> http://lists.rubyonrails.org/mailman/listinfo/rails >>> >>> >> >> >> >> >> >-- Pedro C. Valentini pedro-p14LI7ZcAE/pVLaUnt/cCQC/G2K4zDHf@public.gmane.org +55 (21) 8708-8035
On 4/27/05, Pedro Valentini <pedro-p14LI7ZcAE/pVLaUnt/cCQC/G2K4zDHf@public.gmane.org> wrote:> > I want somethink simple. > Receibe one text in a textfield and show this text in a html page. > But textfield use \n to break lines and html pages <br> > .gsub(''\n'',''<br />'') don''t work... > > What more can I try??Jeremy gave you the answer, in your view put <%= @the_string_you_want_to_show.gsub("\n", "<br />") %>> Thank you > > Heikki Tunkelo escreveu: > > >It depends on what do you want to do. > > > >If you want to do some intellligent formatting for your strings, then > >check out redcloth http://www.whytheluckystiff.net/ruby/redcloth/ > > > >If you just want to output your string "as-is", why not put "<pre>" - > >tags around it. > > > >Heikki > > > >On 4/26/05, Pedro Valentini <pedro-p14LI7ZcAE/pVLaUnt/cCQC/G2K4zDHf@public.gmane.org> wrote: > > > > > >>Hi, > >>how convert string to html (\n to <br />) ? > >>I found only scape and unscapehtml in ruby reference and they don''t do > >>this \n to <br /> > >>I need to use replace ?? > >> > >>Thank you > >> > >>-- > >> > >>Pedro C. Valentini > >>pedro-p14LI7ZcAE/pVLaUnt/cCQC/G2K4zDHf@public.gmane.org > >>+55 (21) 8708-8035 > >> > >>_______________________________________________ > >>Rails mailing list > >>Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > >>http://lists.rubyonrails.org/mailman/listinfo/rails > >> > >> > >> > > > > > > > > > > -- > > Pedro C. Valentini > pedro-p14LI7ZcAE/pVLaUnt/cCQC/G2K4zDHf@public.gmane.org > +55 (21) 8708-8035 > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-- Cheers Koz
It not work, use <%= simple_format(@your_text_variable) %> this helper convert to html... Pedro Michael Koziarski escreveu:>On 4/27/05, Pedro Valentini <pedro-p14LI7ZcAE/pVLaUnt/cCQC/G2K4zDHf@public.gmane.org> wrote: > > >>I want somethink simple. >>Receibe one text in a textfield and show this text in a html page. >>But textfield use \n to break lines and html pages <br> >>.gsub(''\n'',''<br />'') don''t work... >> >>What more can I try?? >> >> > >Jeremy gave you the answer, in your view put > ><%= @the_string_you_want_to_show.gsub("\n", "<br />") %> > > > >>Thank you >> >>Heikki Tunkelo escreveu: >> >> >> >>>It depends on what do you want to do. >>> >>>If you want to do some intellligent formatting for your strings, then >>>check out redcloth http://www.whytheluckystiff.net/ruby/redcloth/ >>> >>>If you just want to output your string "as-is", why not put "<pre>" - >>>tags around it. >>> >>>Heikki >>> >>>On 4/26/05, Pedro Valentini <pedro-p14LI7ZcAE/pVLaUnt/cCQC/G2K4zDHf@public.gmane.org> wrote: >>> >>> >>> >>> >>>>Hi, >>>>how convert string to html (\n to <br />) ? >>>>I found only scape and unscapehtml in ruby reference and they don''t do >>>>this \n to <br /> >>>>I need to use replace ?? >>>> >>>>Thank you >>>> >>>>-- >>>> >>>>Pedro C. Valentini >>>>pedro-p14LI7ZcAE/pVLaUnt/cCQC/G2K4zDHf@public.gmane.org >>>>+55 (21) 8708-8035 >>>> >>>>_______________________________________________ >>>>Rails mailing list >>>>Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org >>>>http://lists.rubyonrails.org/mailman/listinfo/rails >>>> >>>> >>>> >>>> >>>> >>> >>> >>> >>> >>-- >> >>Pedro C. Valentini >>pedro-p14LI7ZcAE/pVLaUnt/cCQC/G2K4zDHf@public.gmane.org >>+55 (21) 8708-8035 >> >>_______________________________________________ >>Rails mailing list >>Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org >>http://lists.rubyonrails.org/mailman/listinfo/rails >> >> >> > > > >-- Pedro C. Valentini pedro-p14LI7ZcAE/pVLaUnt/cCQC/G2K4zDHf@public.gmane.org +55 (21) 8708-8035
Pedro Valentini wrote:> > It not work, > use <%= simple_format(@your_text_variable) %> > this helper convert to html...Glad you found something that works. For your reference, ''\n'' is the two ASCII characters \ and n whereas "\n" is a newline. Note the different between single- and double-quoting. jeremy