Rails truncate helper with link as omit text

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

    Dirty solution... use the method "raw" to unescape it.
    you have to be sure of "sanity" of your content.

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

    raw is a helper acting like html_safe .
    bye

    edit: is not the omission of being escaped , but the result of truncate method.

提交回复
热议问题