user1747389
user1747389

Reputation: 31

Ruby on Rails, trim the text

Why this code is not work?

<%= truncate(post.text, :length => post.text.rindex(".", 500)) %>

I need to trim the text on last dot before 500th symbol.

Upvotes: 0

Views: 767

Answers (1)

Charles Barbier
Charles Barbier

Reputation: 845

Use the :separator option. It will truncate at the dot before 500 characters

truncate(post.text, :length => 500, :separator => '.')

Upvotes: 3

Related Questions