问题是如果我使用<% @description = (truncate(post.content, :separator => '[---MORE---]', :length => 0))%>
然后我尝试打印它 -<%= raw @description %>
我仍然看到所有 html 标签。
truncate
默认情况下转义字符串,但您可以使用将其关闭:escape
option:
@description = (truncate(post.content, :separator => '[---MORE---]', :length => 0, :escape => false))
另一种方法是标记post.content
作为 html 安全:
truncate(post.content.html_safe, ...
如果您这样做,您甚至可以删除raw
.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)