Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add new line using /n in text variable

I have a variable in my view printed on screen as

<%= comment.comment %>

but the output has many new line characters (\n).

How do I get it to actually print new lines whenever we have a \n with comment.comment output?

like image 216
Cameron Aziz Avatar asked Nov 19 '25 06:11

Cameron Aziz


1 Answers

Try this:

<%= comment.comment.gsub(/\n/, '<br />') %>

Else you can also use simple_format. Here:

<%= simple_format(comment.comment) %>
like image 119
shivam Avatar answered Nov 21 '25 20:11

shivam



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!