简体   繁体   中英

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:

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

I tried:

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

But this renders the text with the actual html tags:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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