I want to insert, via RJS a multiline string taken from a textarea. Doing:
$('#description').text('<%= simple_format description %>');
does not work because it will generate something like this:
$('#description').text('<p>first line
<br />second line</p>
<p>fourth line</p>');
Because the string isnt on a single line, the JS call fails. So now that simple_format formatted the string correctly, how can I have it all print on a single line in my RJS file?
Try this:
This replaces the newline character with an escape sequence Javascript understands. Similarly for other characters like carriage-return and tab. Moreover it replaces the ‘ character which is a string delimiter character with an escape sequence for it so that a string such as “It’s mine” does not cause any surprises.