Topic: How to?: "this long string" to "this long..."

Is there a simple way to limit the length of the string and have RoR add the ellipsis where necessary (ie: not cut words in half, but add it at the end of a word)?

If not a built in function, how would one go about creating this functionality?

Thank you

Regards,
Dimitry

[edit]
I found something similar but don't want it to end the string with last words.. simply want the three dots and not sure how to change the code sad
http://www.benjaminbooth.com/tableorboo … et_sh.html

Last edited by dimitry (2007-06-11 02:01:57)

Re: How to?: "this long string" to "this long..."

Yep, truncate method.

truncate(text, length = 30, truncate_string = "...")

truncate("Once upon a time in a world far far away", 14)
   => Once upon a...

Last edited by DFischer (2007-06-11 04:33:58)

http://danielfischer.com - Personal Web-Technology-Blog, Los Angeles.