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