我有一个看起来像这样的字符串:
<p><%= truncate(event.description, length: 450) %></p>
这里是html中呈现的内容:
"Pacific North West Fall Time Paint & Sip Pint Night7:00-9:30pm
It's that time of year for fall leaves, hoodies, pumpkins and s'mores and for our new Fall-themed Painting. Artist Iris Mes Low is developing a Fall-themed painting that will capture the beauty of the Pacific North West. You'll be able to enjoy a glass of wine or beer & light appies while painting your very own masterpiece. We provide all the paint supplies and our artist take..."
除了我的视图是将它全部呈现在一个长字符串中。我想用正确的间距渲染它,如上面HTML中所示。
我试过了:
<p><%= truncate(simple_format(event.description, {}, :sanitize => false), length: 450) %></p>
但是这会使文本与呈现实际的html标记:
<p>Pacific North West Fall Time Paint & Sip Pint Night7:00-9:30pm</p> <p>It's that time of year for fall leaves, hoodies, pumpkins and s'mores and for our new Fall-themed Painting. Artist Iris Mes Low is developing a Fall-themed painting that will capture the beauty of the Pacific North West. You'll be able to enjoy a glass of wine or beer & light appies while painting your very own masterpiece. We provide all the paint supplies and our art...
我该如何解决这个问题?
答案 0 :(得分:0)
有点晚了,但这可以解决你的问题。
<p><%= simple_format(truncate(event.description, {}, :sanitize => false, length: 450)) %></p>