Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Output text size in ruby on rails

How do I get only first (say) 200 characters from my object Article (which is in a table articles with aattributes content and title)?

Thank you

like image 925
necker Avatar asked Dec 02 '25 09:12

necker


1 Answers

The rails' TextHelper has a truncate method.

So, in your views, you just have to do :

<%= truncate @article.content, :length => 50 %>

Where 50 is the number of characters you want to display.

like image 114
Damien MATHIEU Avatar answered Dec 04 '25 00:12

Damien MATHIEU



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!