Rails truncate helper with link as omit text

前端 未结 7 1877
忘掉有多难
忘掉有多难 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:56

    With Rails 4, you can/should pass in a block for the link:

    truncate("Once upon a time in a world far far away", 
      length: 10, 
      separator: ' ', 
      omission: '... ') {     
        link_to "Read more", "#" 
    }
    

提交回复
热议问题