Equivilent to PHP's nl2br?


Hey all, this is a pretty simple question but I can’t seem to find
anything on the wikki or google… Is there a Ruby/Rails equivilent to
PHP’s nl2br function?


simple_format(“whatever\n\n”) => “whatever

found in TextHelper



some_string.gsub!(/\n/, ‘

You also might want to look at Textile
(http://www.textism.com/tools/textile/index.php) or Markdown


Awsomr, thanks to both of you!


I wrote a helper function:

def nl2br(string)
").gsub("\r", “”).gsub("\n", “

This seems to work fairly well. I put it in the application helper
wherever I think I’ll need it. I feed it html, say like this: nl2br(h

You could certainly modify it so that it automatically wraps the
input in an h().

Nicholas P. Mueller