2012-12-23 2 views
0

3.0 사용 살균 및 simple_format, 나는 pibr 등과 같은 안전 html 태그 일부 단락을 렌더링 (및 잘라 내기) 할,이 코드를 사용 html 태그가있는 단락 나는이보기 내 application_helper레일 내보기에 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> 

어떻게 그것을 해결하기 위해

를 렌더링? 안전 태그로 단락을 렌더링하는 더 좋은 방법이 있습니까? 그것을 할 수

답변

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 
관련 문제