Rails의 ActionView::Helpers::TextHelper에 있는 truncate method는 한글을 자를 때, 정확히 처리하지를
못한다. 다음의 truncate method를 application_helper에 등록해 두면, view page에서 한글을 정확히 자를 수
있다. UTF-8 문자를 한글, 영어 모두 1글자씩으로 처리해서 자르게된다.
못한다. 다음의 truncate method를 application_helper에 등록해 두면, view page에서 한글을 정확히 자를 수
있다. UTF-8 문자를 한글, 영어 모두 1글자씩으로 처리해서 자르게된다.
- def truncate(text, len, tail = '...')
- unpacked = text.unpack('U*')
- unpacked.length > len ? unpacked[0..len-1].pack('U*') + tail : text
- end



::: 사람과 사람의 교감! 人터넷의 첫 시작! 댓글을 달아주세요! :::