Hi all, Is there no way to easily resolve this. It can''t be that I''m the first that wants this, and it wouldn''t be RoR if it''s not possible. On the mysql prompt with the select description from todos .. linefeeds are show, so they are there. This is the actual contents with a linefeed after the ":" "Project contacts: delete table, point project to contacts" But this: <%= todo.description.tr(''\n'', ''<br />'') %> Results in this: Project co (It actually replaces "n",and it''s on to the next cell) And with double quotes int the statement it''s this: "Project contacts:" (and it''s on to the next cell). Tried RedCloth but that doesn''t work as simple either (not at all actually, because it doesn''t know textilize or textile as a methgod after install) Help is greately appreciated. Regards, Gerard. -- "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!
Hi Gerard, regarding RedCloth: sounds as if you didn''t make rails to know about RedCloth. Is require ''rubygems'' require_gem ''RedCloth'' in your environment.rb? whats .tr about (don''t know this method). You might have a try with todo.description.gsub(''\n'', ''<br />'') Best Regards Jan Prill Gerard Petersen wrote:> Hi all, > > Is there no way to easily resolve this. It can''t be that I''m the first that > wants this, and it wouldn''t be RoR if it''s not possible. > > On the mysql prompt with the select description from todos .. linefeeds are > show, so they are there. > > This is the actual contents with a linefeed after the ":" > > "Project contacts: > delete table, point project to contacts" > > But this: <%= todo.description.tr(''\n'', ''<br />'') %> > > Results in this: > > Project co > (It actually replaces "n",and it''s on to the next cell) > > And with double quotes int the statement it''s this: > > "Project contacts:" > > (and it''s on to the next cell). > > Tried RedCloth but that doesn''t work as simple either (not at all actually, > because it doesn''t know textilize or textile as a methgod after install) > > Help is greately appreciated. > > Regards, > > Gerard. > >
Jan, Found it after chewing on your input. This one does the trick. gsub should be written with slashes: <%= todo.description.gsub(/\n/, ''<br />'') %>< What still confuses me though is that redcloth is not available:> require ''rubygems'' > require_gem ''RedCloth''I put these in and restarted webrick. WIth the result: undefined method `textile'' for "Project contacts:\ndelete table, point project to contacts":String (textilize doesn''t work either)> whats .tr about (don''t know this method). You might have a try with > todo.description.gsub(''\n'', ''<br />'')I''ve seen the "tr" come by somewhere in this list and is mentioned on the ruby book: http://www.ruby-doc.org/docs/ProgrammingRuby/ Under: http://www.ruby-doc.org/docs/ProgrammingRuby/html/ref_c_string.html#String.tr Thanx a lot! Regards, Gerard.> > Best Regards > Jan Prill > > Gerard Petersen wrote: > > Hi all, > > > > Is there no way to easily resolve this. It can''t be that I''m the first > > that wants this, and it wouldn''t be RoR if it''s not possible. > > > > On the mysql prompt with the select description from todos .. linefeeds > > are show, so they are there. > > > > This is the actual contents with a linefeed after the ":" > > > > "Project contacts: > > delete table, point project to contacts" > > > > But this: <%= todo.description.tr(''\n'', ''<br />'') %> > > > > Results in this: > > > > Project co > > (It actually replaces "n",and it''s on to the next cell) > > > > And with double quotes int the statement it''s this: > > > > "Project contacts:" > > > > (and it''s on to the next cell). > > > > Tried RedCloth but that doesn''t work as simple either (not at all > > actually, because it doesn''t know textilize or textile as a methgod after > > install) > > > > Help is greately appreciated. > > > > Regards, > > > > Gerard. > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails-- "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!
String#tr is for translating single characters to other single characters. You can''t replace a single character with more than one characer using tr. Use String#gsub instead. todo.description.gsub( "\n", "<br />" ) On 1/17/06, Gerard Petersen <mailing@gp-net.nl> wrote:> Hi all, > > Is there no way to easily resolve this. It can''t be that I''m the first that > wants this, and it wouldn''t be RoR if it''s not possible. > > On the mysql prompt with the select description from todos .. linefeeds are > show, so they are there. > > This is the actual contents with a linefeed after the ":" > > "Project contacts: > delete table, point project to contacts" > > But this: <%= todo.description.tr(''\n'', ''<br />'') %> > > Results in this: > > Project co > (It actually replaces "n",and it''s on to the next cell) > > And with double quotes int the statement it''s this: > > "Project contacts:" > > (and it''s on to the next cell). > > Tried RedCloth but that doesn''t work as simple either (not at all actually, > because it doesn''t know textilize or textile as a methgod after install) > > Help is greately appreciated. > > Regards, > > Gerard. > > > -- > "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 >-- - Mik Mifflin "Whether freedom is going to survive at all is in doubt, but we''ve got to try" - RMS
On Tue, Jan 17, 2006 at 10:10:28PM +0100, Gerard Petersen wrote:> This is the actual contents with a linefeed after the ":" > > "Project contacts: > delete table, point project to contacts" > > But this: <%= todo.description.tr(''\n'', ''<br />'') %> > > Results in this: > > Project co > (It actually replaces "n",and it''s on to the next cell)(Taking into account your later e-mails as well) The problem isn''t that you need to feed gsub a regex (which is what /\n/ actually gives you) but rather than single quotes don''t expand escape sequences like \n. What you really needed was gsub("\n", ''<br />'') instead, which gives you the correct result. - Matt
I figured I would just add that you may want to use the "simple_format" function - it doesn''t just do \n to <br /> but a few other things and wraps in a <p> tag - not always desirable but since you were considering using Textile I figured it was worth mentioning. Docs on simple_format are here: http://api.rubyonrails.com/classes/ActionView/Helpers/TextHelper.html#M000425 If you take a look at the source it shows you''ll see it''s some regexs, nothing fancy, but nevertheless useful.
Gerard: On Jan 17, 2006, at 1:10 PM, Gerard Petersen wrote:> > But this: <%= todo.description.tr(''\n'', ''<br />'') %><%= todo.description.gsub ''\n'',''<br />'' %> works on your example string. Cheers, Hasan Diwan <hasan.diwan@gmail.com> -------------- next part -------------- A non-text attachment was scrubbed... Name: PGP.sig Type: application/pgp-signature Size: 186 bytes Desc: This is a digitally signed message part Url : http://wrath.rubyonrails.org/pipermail/rails/attachments/20060118/0941f3bf/PGP.bin
Hmm .. so ''\n'' would be expanded before used, that right? GrtzG On Wednesday 18 January 2006 00:11, Matthew Palmer tried to type something like:> On Tue, Jan 17, 2006 at 10:10:28PM +0100, Gerard Petersen wrote: > > This is the actual contents with a linefeed after the ":" > > > > "Project contacts: > > delete table, point project to contacts" > > > > But this: <%= todo.description.tr(''\n'', ''<br />'') %> > > > > Results in this: > > > > Project co > > (It actually replaces "n",and it''s on to the next cell) > > (Taking into account your later e-mails as well) > > The problem isn''t that you need to feed gsub a regex (which is what /\n/ > actually gives you) but rather than single quotes don''t expand escape > sequences like \n. What you really needed was gsub("\n", ''<br />'') > instead, which gives you the correct result. > > - Matt > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails-- "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!
Looks nice TNX! Although I got it working with gsub I''m still wondering why RedCloth is nagging me with unknown method errors .. :-( GrtzG On Wednesday 18 January 2006 00:27, Jonathan Dance tried to type something like:> I figured I would just add that you may want to use the > "simple_format" function - it doesn''t just do \n to <br /> but a few > other things and wraps in a <p> tag - not always desirable but since > you were considering using Textile I figured it was worth mentioning. > > Docs on simple_format are here: > http://api.rubyonrails.com/classes/ActionView/Helpers/TextHelper.html#M0004 >25 > > If you take a look at the source it shows you''ll see it''s some regexs, > nothing fancy, but nevertheless useful. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails-- "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!
''\n'' is a two character string ''\n''[0] => \ and ''\n''[1] => n "\n" is a one character string get your ascii chart and fire up irb! irb(main):001:0> ''\n''[0] => 92 irb(main):002:0> ''\n''[1] => 110 irb(main):003:0> "\n"[0] => 10 irb(main):004:0> "\n"[1] => nil irb(main):005:0> single-quoted strings don''t interpolate their contents, not even for \-escapes -Rob At 1/18/2006 06:45 PM, Gerard Petersen wrote:>Hmm .. so ''\n'' would be expanded before used, that right? > >GrtzG > >On Wednesday 18 January 2006 00:11, Matthew Palmer tried to type something >like: > > On Tue, Jan 17, 2006 at 10:10:28PM +0100, Gerard Petersen wrote: > > > This is the actual contents with a linefeed after the ":" > > > > > > "Project contacts: > > > delete table, point project to contacts" > > > > > > But this: <%= todo.description.tr(''\n'', ''<br />'') %> > > > > > > Results in this: > > > > > > Project co > > > (It actually replaces "n",and it''s on to the next cell) > > > > (Taking into account your later e-mails as well) > > > > The problem isn''t that you need to feed gsub a regex (which is what /\n/ > > actually gives you) but rather than single quotes don''t expand escape > > sequences like \n. What you really needed was gsub("\n", ''<br />'') > > instead, which gives you the correct result. > > > > - Matt > > _______________________________________________ > > Rails mailing list > > Rails@lists.rubyonrails.org > > http://lists.rubyonrails.org/mailman/listinfo/rails > >-- >"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 weird, it didn''t when used in the template. any idea? GrtzG On Wednesday 18 January 2006 18:55, Hasan Diwan tried to type something like:> Gerard: > > On Jan 17, 2006, at 1:10 PM, Gerard Petersen wrote: > > But this: <%= todo.description.tr(''\n'', ''<br />'') %> > > <%= todo.description.gsub ''\n'',''<br />'' %> works on your example string. > Cheers, > Hasan Diwan <hasan.diwan@gmail.com>-- "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''ll hack on that thanks! So those win cr/lf''s would contain two chars then when in between doubles? GrtzG On Thursday 19 January 2006 00:55, Rob Biedenharn tried to type something like:> ''\n'' is a two character string ''\n''[0] => \ and ''\n''[1] => n > "\n" is a one character string > > get your ascii chart and fire up irb! > > irb(main):001:0> ''\n''[0] > => 92 > irb(main):002:0> ''\n''[1] > => 110 > irb(main):003:0> "\n"[0] > => 10 > irb(main):004:0> "\n"[1] > => nil > irb(main):005:0> > > > single-quoted strings don''t interpolate their contents, not even for > \-escapes > > -Rob > > At 1/18/2006 06:45 PM, Gerard Petersen wrote: > >Hmm .. so ''\n'' would be expanded before used, that right? > > > >GrtzG > > > >On Wednesday 18 January 2006 00:11, Matthew Palmer tried to type something > > > >like: > > > On Tue, Jan 17, 2006 at 10:10:28PM +0100, Gerard Petersen wrote: > > > > This is the actual contents with a linefeed after the ":" > > > > > > > > "Project contacts: > > > > delete table, point project to contacts" > > > > > > > > But this: <%= todo.description.tr(''\n'', ''<br />'') %> > > > > > > > > Results in this: > > > > > > > > Project co > > > > (It actually replaces "n",and it''s on to the next cell) > > > > > > (Taking into account your later e-mails as well) > > > > > > The problem isn''t that you need to feed gsub a regex (which is what > > > /\n/ actually gives you) but rather than single quotes don''t expand > > > escape sequences like \n. What you really needed was gsub("\n", ''<br > > > />'') instead, which gives you the correct result. > > > > > > - Matt > > > _______________________________________________ > > > Rails mailing list > > > Rails@lists.rubyonrails.org > > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > >-- > >"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-- "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!
On Thu, Jan 19, 2006 at 12:45:57AM +0100, Gerard Petersen wrote:> On Wednesday 18 January 2006 00:11, Matthew Palmer tried to type something > like: > > On Tue, Jan 17, 2006 at 10:10:28PM +0100, Gerard Petersen wrote: > > > This is the actual contents with a linefeed after the ":" > > > > > > "Project contacts: > > > delete table, point project to contacts" > > > > > > But this: <%= todo.description.tr(''\n'', ''<br />'') %> > > > > > > Results in this: > > > > > > Project co > > > (It actually replaces "n",and it''s on to the next cell) > > > > (Taking into account your later e-mails as well) > > > > The problem isn''t that you need to feed gsub a regex (which is what /\n/ > > actually gives you) but rather than single quotes don''t expand escape > > sequences like \n. What you really needed was gsub("\n", ''<br />'') > > instead, which gives you the correct result. > > Hmm .. so ''\n'' would be expanded before used, that right?No, ''\n'' is a two character String object -- a literal backslash followed by a literal lowercase n. "\n" is a single character String object, containing the newline character ASCII code 0x0A. (On windows, "\n" *may* expand to the two-character String object 0x0D 0x0A under some circumstances, but I''ve got no experience with Ruby on windows, so if you''re on windows you''re on your own). - Matt
At 1/18/2006 07:21 PM, Matt Palmer wrote:>On Thu, Jan 19, 2006 at 12:45:57AM +0100, Gerard Petersen wrote: > > On Wednesday 18 January 2006 00:11, Matthew Palmer tried to type something > > like: > > > On Tue, Jan 17, 2006 at 10:10:28PM +0100, Gerard Petersen wrote: > > > > This is the actual contents with a linefeed after the ":" > > > > > > > > "Project contacts: > > > > delete table, point project to contacts" > > > > > > > > But this: <%= todo.description.tr(''\n'', ''<br />'') %> > > > > > > > > Results in this: > > > > > > > > Project co > > > > (It actually replaces "n",and it''s on to the next cell) > > > > > > (Taking into account your later e-mails as well) > > > > > > The problem isn''t that you need to feed gsub a regex (which is what /\n/ > > > actually gives you) but rather than single quotes don''t expand escape > > > sequences like \n. What you really needed was gsub("\n", ''<br />'') > > > instead, which gives you the correct result. > > > > Hmm .. so ''\n'' would be expanded before used, that right? > >No, ''\n'' is a two character String object -- a literal backslash followed by >a literal lowercase n. "\n" is a single character String object, containing >the newline character ASCII code 0x0A. (On windows, "\n" *may* expand to >the two-character String object 0x0D 0x0A under some circumstances, but I''ve >got no experience with Ruby on windows, so if you''re on windows you''re on >your own). > >- Matt*nix or Windoze, doesn''t seem to matter here: $ uname Linux $ irb irb(main):001:0> ''\n''.length => 2 irb(main):002:0> "\n".length => 1 irb(main):003:0> "\n"[0] => 10 irb(main):004:0> Microsoft Windows XP [Version 5.1.2600] (C) Copyright 1985-2001 Microsoft Corp. C:\>irb irb(main):001:0> ''\n''.length => 2 irb(main):002:0> "\n".length => 1 irb(main):003:0> "\n"[0] => 10 irb(main):004:0> -Rob
No windows for me thanx. I was just curious. TNX and Grtz Gerard. On Thursday 19 January 2006 01:21, Matt Palmer tried to type something like:> On Thu, Jan 19, 2006 at 12:45:57AM +0100, Gerard Petersen wrote: > > On Wednesday 18 January 2006 00:11, Matthew Palmer tried to type > > something > > > > like: > > > On Tue, Jan 17, 2006 at 10:10:28PM +0100, Gerard Petersen wrote: > > > > This is the actual contents with a linefeed after the ":" > > > > > > > > "Project contacts: > > > > delete table, point project to contacts" > > > > > > > > But this: <%= todo.description.tr(''\n'', ''<br />'') %> > > > > > > > > Results in this: > > > > > > > > Project co > > > > (It actually replaces "n",and it''s on to the next cell) > > > > > > (Taking into account your later e-mails as well) > > > > > > The problem isn''t that you need to feed gsub a regex (which is what > > > /\n/ actually gives you) but rather than single quotes don''t expand > > > escape sequences like \n. What you really needed was gsub("\n", ''<br > > > />'') instead, which gives you the correct result. > > > > Hmm .. so ''\n'' would be expanded before used, that right? > > No, ''\n'' is a two character String object -- a literal backslash followed > by a literal lowercase n. "\n" is a single character String object, > containing the newline character ASCII code 0x0A. (On windows, "\n" *may* > expand to the two-character String object 0x0D 0x0A under some > circumstances, but I''ve got no experience with Ruby on windows, so if > you''re on windows you''re on your own). > > - Matt > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails-- "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!