在我看来,我想用p
i
br
等安全的html标签渲染(并截断)某个段落,我使用此代码:
- @last_testimony.each do |last_testimony|
= sanitize(simple_format(truncate(last_testimony.description, :length => 25)), :tags => %w(p i br b))
它使用html标记呈现段落。
但是当我将该代码传递给我的application_helper
时def paragraph(text, length)
"#{sanitize(simple_format(truncate(text, :length => length)), :tags => %w(p i br b))}"
end
有了这个观点
- @last_testimony.each do |last_testimony|
= paragraph(last_testimony.description, 10)
呈现
< p>My paragraph < /p>
如何解决?有没有更好的方法来呈现带有安全标签的段落?
答案 0 :(得分:2)
一些方法:
1
- @last_testimony.each do |last_testimony|
= raw paragraph(last_testimony.description, 10)
2
def paragraph(text, length)
"#{sanitize(simple_format(truncate(text, :length => length)), :tags => %w(p i br b))}".html_safe
end