繁体   English   中英

Rails:simple_format正在呈现html标签

[英]Rails : simple_format is rendering html tags

我有一个看起来像这样的字符串:

 <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...

我怎样才能解决这个问题?

有点晚了,但这应该可以解决您的问题。

  <p><%= simple_format(truncate(event.description, {}, :sanitize => false, length: 450)) %></p>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM