Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Want to show the first 50 or 60 words of a text field in ruby?

I have a stories text field and want to show the first few lines – say the first 50 words of that field – in a snapshot page. How can I do that in Ruby (on Rails)?

like image 887
Arc Avatar asked Dec 23 '22 12:12

Arc


1 Answers

Assuming your words are delimited by a space, you can do something like this.

stories.split(' ').slice(0,50).join(' ')
like image 194
Aaron Hinni Avatar answered Feb 16 '23 00:02

Aaron Hinni