Hi!
I have a really stupid/simple question. How do you go about limiting
the size of a field for the output? For example, I have a field that
says...
<td><%= response.description %></td>
in my list.rhtml file. However, the description, at times, is rather
long. How can I limit it to say, 15 or so characters and then just
chop off the rest of the text?
Thanks!
Mike
<td><%= response.description.to(15) %></td>
-Bill
wiz561@gmail.com wrote:
I have a really stupid/simple question. How do you go about limiting
the size of a field for the output? For example, I have a field that
says...
<td><%= response.description %></td>
in my list.rhtml file. However, the description, at times, is rather
long. How can I limit it to say, 15 or so characters and then just
chop off the rest of the text?
truncate(response.description, 15)
truncate(text, length = 30, truncate_string = "...")
If text is longer than length, text will be truncated to the length of length and the last three characters will be replaced with the truncate_string.
truncate("Once upon a time in a world far far away", 14)
=> Once upon a...
Just be careful about chopping it right in the middle of an html tag...
-philip
Thank you very much Bill. That .to(15) did the trick...and so
easy. 
Thanks,
Mike