This project is archived and is in readonly mode.

#1807 ✓resolved
Andy Stewart

Augment truncate helper to accept a separator

Reported by Andy Stewart | January 28th, 2009 @ 04:56 PM | in 2.x

The truncate text helper currently cuts off the given text mid-word if that's where the length limit is reached.

This backwards-compatible patch allows you to pass the :separator option to make the truncated result end at the last occurrence of the given separator (within the length allowed).

If you don't pass the :separator option the helper behaves as it currently does. This means that all existing code will continue to work the same way.

Typically you would use this to have the truncated text finish at the end of a word.

For example:

truncate("Once upon a time in a world far far away")

=> Once upon a time in a world f...

truncate("Once upon a time in a world far far away", :separator => ' ')

=> Once upon a time in a world...

Comments and changes to this ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

People watching this ticket

Attachments

Referenced by

Pages