简体   繁体   English

Rails:simple_format正在呈现html标签

[英]Rails : simple_format is rendering html tags

I have a string that looks like this: 我有一个看起来像这样的字符串:

 <p><%= truncate(event.description, length: 450) %></p>

Here's what renders in the html: 这是在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..."

Except my view is rendering it all in one long string. 除了我的观点,所有内容都以一个长字符串呈现。 I'd like to render it with the correct spacing like it shows in above HTML. 我想以正确的间距渲染它,就像上面HTML中显示的那样。

I tried: 我试过了:

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

But this renders the text with the actual html tags: 但这会使用实际的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...

How can I fix this? 我怎样才能解决这个问题?

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

  <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