私の見解では、安全な 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
この見方で
- @last_testimony.each do |last_testimony|
= paragraph(last_testimony.description, 10)
それはレンダリングします
< p>My paragraph < /p>
修正方法は?安全なタグを使用して段落をレンダリングするより良い方法はありますか?