Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to achieve text extract on rails?

I have an article list page. It needs to show some content information about this article. If I only use:

 truncate @article.content,:length=>100

It will show some html tag, and doesn't show the real content to the user. I want to find some way to get the text extract from the content, so I want to ask is there some embedded way to achieve this?

like image 875
mlzboy Avatar asked Nov 23 '10 07:11

mlzboy


1 Answers

You could use strip_tags to remove the html tags:

truncate(strip_tags(@article.content), :length=>100)
like image 196
Petrik de Heus Avatar answered Sep 26 '22 23:09

Petrik de Heus