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
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
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.
irb(main):004:0> '0123456789'[3,7]
=> "3456789"
irb(main):005:0> '0123456789'[3..7]
=> "34567"
irb(main):006:0> '0123456789'[3...7]
=> "3456"
Above code and outputs are self explanatory.