Its all about Ruby On Rails
converting all newline characters to br tag
I was surprised as there is no function in ruby to convert all newline characters to <br>.
Here is a php nl2br equivalent method to convert all newline characters (\n) to break tag (<br>) in a string.
def nl2br(s)
s.gsub(/\\n/, '<br>')
end
August 8, 2006 - 2:42 pm
def nl2br(s)
s.gsub(/\n/, ”)
end
This would be more appropriate
August 18, 2006 - 12:30 pm
This will remove all new line characters not replace them by <br>
May 18, 2007 - 8:01 pm
I believe he was reffering to the /\n/ part. Since /n/ will remove all n-characthers and replace them with
May 21, 2007 - 11:51 pm
simple_format text helper do the trick
http://api.rubyonrails.org/classes/ActionView/Helpers/TextHelper.html#M000623