wiz561-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2007-Oct-25 21:40 UTC
Limiting Size of Output Field
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 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
<td><%= response.description.to(15) %></td> -Bill wiz561-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org wrote:> 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 > > > > >-- Sincerely, William Pratt --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
> 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 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
wiz561-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2007-Oct-26 13:56 UTC
Re: Limiting Size of Output Field
Thank you very much Bill. That .to(15) did the trick...and so easy. :) Thanks, Mike On Oct 25, 5:27 pm, William Pratt <bi...-YbheRAKfYF4eIZ0/mPfg9Q@public.gmane.org> wrote:> <td><%= response.description.to(15) %></td> > > -Bill > > > > wiz...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org wrote: > > 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 > > -- > Sincerely, > > William Pratt--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---