I'm building a cms for video management that includes transcript fields. The transcript fields get sent to the database and almost always have multiple newline ("\n") characters.
I'm running rails 4.2 with bootstrap.
Probably not relevant, but the code:
# Controller
class VideosController < ApplicationController
def show
@video = Video.find(params[:id])
end
end
# View (in haml)
.panel.panel-default
.panel-body
%p= @video.transcript
Is there a clean way to render the line breaks properly in html?
Check the simple_format
helper:
Returns text transformed into HTML using simple formatting rules. Two or more consecutive newlines(
\n\n
) are considered as a paragraph and wrapped in<p>
tags. One newline (\n
) is considered as a linebreak and a<br />
tag is appended. This method does not remove the newlines from the text.
.panel.panel-default
.panel-body
%p= simple_format(@video.transcript)
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