Rails truncate helper with link as omit text

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

    I had the same problem, in my case i just used :escape => false. That worked:

    truncate article.description, :length => 200, :omission => "... #{link_to('[more]', articles_path(article)}", :escape => false

    From documentation :

    The result is marked as HTML-safe, but it is escaped by default, unless :escape is false.... link: http://apidock.com/rails/ActionView/Helpers/TextHelper/truncate

提交回复
热议问题