String cutter

Hey,

I am wondering if there is some kind of built in function to strip the
text to given length, but I dont want to cut the word in the middle. :slight_smile:

I know that this works, but it cuts the text.
<%= @post.body[0…60] %>

Is there a way to do the same thing but keep the last word as it is or
if the length of the word is longer than given size, strip the whole
word, not just the part of it.

Thank you.
P.

On 12 Jun 2009, at 12:11, Petan C. wrote:

I am wondering if there is some kind of built in function to strip the
text to given length, but I dont want to cut the word in the
middle. :slight_smile:

I know that this works, but it cuts the text.
<%= @post.body[0…60] %>

Is there a way to do the same thing but keep the last word as it is or
if the length of the word is longer than given size, strip the whole
word, not just the part of it.

Best regards

Peter De Berdt

Thank you,
that is exactly what I was looking for.

Cheeers.
P.

Awesome Truncation in Rails - mlcastle

Best regards

Peter De Berdt