在我看来,我想渲染(和截断)一些段落与安全的html标签,如p
i
br
等,我使用这个代码:
- @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
With this view
- @last_testimony.each do |last_testimony|
= paragraph(last_testimony.description, 10)
它呈现
< p>My paragraph < /p>
如何修复?是否有更好的方法来呈现带有安全标签的段落?
一些方法:
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