Equivilent to PHP's nl2br?


#1

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?


#2

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


found in TextHelper


#3

Try

some_string.gsub!(/\n/, ‘
’)

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


#4

Awsomr, thanks to both of you!


#5

I wrote a helper function:

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

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
(@object.text))

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

Nicholas P. Mueller