Rails truncate helper with link as omit text

前端 未结 7 1896
忘掉有多难
忘掉有多难 2021-02-06 01:27

I\'m quite long description that I want to truncate using truncate helper. So i\'m using the:

truncate article.description, :length => 200, :omission => \         


        
7条回答
  •  面向向阳花
    2021-02-06 01:46

    TextHelper#truncate has a block form of truncate, which lets you use a link_to that isn't escaped, while still escaping the truncated text:

    truncate("") { link_to "Read More", "#" }
    
    #=> <script>alert('hello world'...Read More
    

提交回复
热议问题