def convert_link_in_string( string )
regex = "\\b(https?|ftp|file)://[-a-zA-Z0-9+&@#/%?=~_|!:,.;]*[-a-zA-Z0-9+&@#/%=~_|]"
content = string
if string.match( regex ).present? && string.match( regex )[0].present? && string.match( regex )[0].include?('http')
link = string.match( regex )[0]
content = string.gsub(link, "<a href=#{ link } target='_blank'>#{ link }</a>")
end
return raw( content )
end
'Ruby on Rails' 카테고리의 다른 글
Devise로 이메일 인증 구현하기 (0) | 2018.07.27 |
---|---|
루비 정규식 테스트 사이트 (0) | 2018.07.17 |
인덱스가 걸려있는 컬럼을 지우면 어떻게 될까? (0) | 2018.03.13 |
레일즈 벨리데이션은 믿을 수 있는가? (0) | 2017.09.07 |