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

Try

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)
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

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs