Rails truncate helper with link as omit text

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

    I would suggest doing this on your own in a helper method, that way you'll have a little more control over the output as well:

    def article_description article
      output = h truncate(article.description, length: 200, omission: '...')
      output += link_to('[more]', article_path(article)) if article.description.size > 200
      output.html_safe
    end
    

提交回复
热议问题