Forum: Ruby on Rails Cut off text if its too big for a table? (Resize table?)

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Tim M. (Guest)
on 2009-03-06 19:48
I made a nice (imo), custom table for my posts while following a simple
blog in Rails tutorial. I was wondering tho if I can set a maximum width
for a table row/cell and have it cut off text if its too long to fit, so
it just shows a preview of the blog post. Also, is it possible for the
table to size and get  bigger with the resizing of a browser window? I
know that this is mostly an HTML problem, so I'm sorry if this is the
wrong place.
Bob M. (Guest)
on 2009-03-06 19:52
(Received via mailing list)
There should be a way to just limit the number of words displayed from
a certain field. Do it that way and then you'll have some consistency.
I can't think at the moment, but I would think there is a way to limit
the number of words to just a certain limit relatively easily in Ruby/
Rails.
bill walton (Guest)
on 2009-03-06 22:57
(Received via mailing list)
Hi Tim,

On Fri, 2009-03-06 at 18:48 +0100, Tim M. wrote:
> I made a nice (imo), custom table for my posts while following a simple
> blog in Rails tutorial. I was wondering tho if I can set a maximum width
> for a table row/cell and have it cut off text if its too long to fit, so
> it just shows a preview of the blog post. Also, is it possible for the
> table to size and get  bigger with the resizing of a browser window? I
> know that this is mostly an HTML problem, so I'm sorry if this is the
> wrong place.

I can think of a couple of ways to approach this.

CSS overflow - not sure if this works with table elements, but you can
set the overflow attribute in a CSS rule to simply clip content to the
element size, make the element scroll, or a couple of other choices.

Helper methods - either a view helper, or a method in your model, can
trim the string prior to display; assuming you know the size you want to
trim it to.

I prefer the CSS approach because it's simpler.  It'll automatically
take care of the resizing issue.  But, like I said, I'm not sure if it's
supported with table elements.  Make a test and let us know.

HTH,
Bill
Morgan M. (Guest)
on 2009-03-07 00:24
Tim M. wrote:
> I made a nice (imo), custom table for my posts while following a simple
> blog in Rails tutorial. I was wondering tho if I can set a maximum width
> for a table row/cell and have it cut off text if its too long to fit, so
> it just shows a preview of the blog post. Also, is it possible for the
> table to size and get  bigger with the resizing of a browser window? I
> know that this is mostly an HTML problem, so I'm sorry if this is the
> wrong place.

i agree with the previous post that you should just limit your word
count so it would just kill anything over the limit and replace it with
a link "...."  that goes to full text...

that seems to be the bog standard way to do it.
This topic is locked and can not be replied to.