How would I go about allowing users to input multi-line text in a text_area
form field?
Currently anytime content is entered in the text area
the line breaks are removed... They are retained when I edit the content... So, maybe it's in the show view that the breaks are being removed?
I've found a few things that indicate that I'd need to implement a WYSIWYG editor, but I'd prefer to avoid that if possible.
Any suggestions?
UPDATE: So, it looks like rails saves the content with line breaks, and I can add .html_safe
to the field in the show view (i.e. <%= @post.post.html_safe %>
). Now it will present content with basic html (e.g. <br>
, <b>
, etc...) but still doesn't present the line breaks in the content (i.e. when I press enter for a new line) that are saved by rails and I can view when I'm editing the content.
Linebreaks are not rendered in HTML. You will want to use something like simple_format or wraptext on your content as you echo it out to convert newlines to <br>
or <p>
tags.
<%=simple_format(@post.post).html_safe %>
or
<%=Wraptext::Parser.new(@post.post).to_html.html_safe %>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With