How to get only the first (say) 200 characters from my Article object (which is in the table articleswith attributes contentand title)?
articles
content
title
thanks
TextHelper rails have a method truncate.
truncate
So in your views you just need 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"
The above code and outputs are explanatory.
; Auto_excerpt, github. https://github.com/RipTheJacker/auto_excerpt.
Source: https://habr.com/ru/post/1722435/More articles:How to programmatically determine the Java byte code version of the current class? - javaChange all views and saved priorities, find and replace? - sqlpassing pointers or integral types through performSelector - c ++Shared folder with world data in the world of Vista / Windows 7 applications - windows-7Pointer indication is not deleted - c ++How to enable scrollbars in silverlight 3.0 - c #How can I update a div continuously - jqueryЗачем нужны вторичные файлы данных в SQL Server? - sql-servereval during emacs lisp macro expansion - macrosDetecting double keystroke of Ctrl in JS - javascriptAll Articles