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?
on 2006-04-13 19:16
on 2006-04-13 19:27
simple_format("whatever\n\n") => "whatever<br/><br/>" found in TextHelper
on 2006-04-13 19:30
Try some_string.gsub!(/\n/, '<br />') You also might want to look at Textile (http://www.textism.com/tools/textile/index.php) or Markdown
on 2006-04-13 19:31
Awsomr, thanks to both of you!
on 2006-04-13 20:01
I wrote a helper function: def nl2br(string) string.gsub("\n\r","<br>").gsub("\r", "").gsub("\n", "<br />") 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