I have Person.description with the following stored in the database:
jnkl
fdsfdsf
fdsf
fsdfdsfs fds fd sf sdf ds
How do I display this with the line-breaks in the view? It is currently displaying all on one line and I don't understand why.
When you add a line break in HTML, you avoid this text wrapping and start new text the next line. To add a line break to your HTML code, you use the <br> tag. The <br> tag does not have an end tag. You can also add additional lines between paragraphs by using the <br> tags.
Microsoft Outlook removes line breaks in signatures for messages sent in plain text format. For the sender, the message looks normal but when displayed to the recipient, line breaks are removed so the formatting of the signature is compromised.
you should use the simple_format helper:
<%= simple_format @person.description %>
http://api.rubyonrails.org/classes/ActionView/Helpers/TextHelper.html#method-i-simple_format
# File actionview/lib/action_view/helpers/text_helper.rb, line 301
def simple_format(text, html_options = {}, options = {})
wrapper_tag = options.fetch(:wrapper_tag, :p)
text = sanitize(text) if options.fetch(:sanitize, true)
paragraphs = split_paragraphs(text)
if paragraphs.empty?
content_tag(wrapper_tag, nil, html_options)
else
paragraphs.map! { |paragraph|
content_tag(wrapper_tag, raw(paragraph), html_options)
}.join("\n\n").html_safe
end
end
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