This is more of a ruby question, but I have a textarea in a form, and for later presentation I need to convert the line endings to <br>.
The value from the form is, for example "line of text\r\nmore text".
I tried gsub('\r\n', "<br>"), but it doesn't find the \r\n. How do I specify those characters?
You would need to use double quotes around \r\n, "\r\n", or express it
as a regex, /\r\n/.
But see also the built-in simple_format helper.
Thanks. I added that after the \r\n line. I figured one of them has to work.
But then I tried out the simple_format that Bob Showalter suggested, which seems to be a better way to do it.
rails has its own simple_format function, it may meet your need.
Returns text transformed into HTML using very simple formatting rules
Surrounds paragraphs with <p> tags, and converts line breaks
into <br /> Two consecutive newlines(\n\n) are considered as a
paragraph, one newline (\n) is considered a linebreak, three or more
consecutive newlines are turned into two newlines