I’m using the trunk8 jquery plug-in with rails (http://jrvis.com/trunk8/#toggle) and it only truncates the first few sentences until the first breaking space. Here’s my code:
<%= simple_format(@post.summary, id:"t8-toggle") %>
How do I ensure that it truncates the whole post? Thanks!
Use the
linesparameter to specify the number of lines of text to display before truncating. By default, trunk8 will only truncate one line of text. Here’s an example: http://jrvis.com/trunk8/#linesCombined with the toggle example, your JavaScript should look something like this:
The advantage of using trunk8 is that it maximizes the amount of visible text before truncating. By using the code in Brian Petro’s answer, you would be truncating after a fixed number of characters, which may or may not be optimal.
Disclosure: I am the creator of the trunk8 plugin.