# Cut off text if its too big for a table? (Resize table?)

**URL:** <https://www.ruby-forum.com/t/cut-off-text-if-its-too-big-for-a-table-resize-table/162200>\
**Category:** Rails\
**Created:** [March 6, 2009, 6:48pm UTC](https://www.ruby-forum.com/t/cut-off-text-if-its-too-big-for-a-table-resize-table/162200 "2009-03-06T18:48:21Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![enchanter](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/ce7236/32.png) [@enchanter](https://www.ruby-forum.com/u/enchanter)\
**Post date:** [March 6, 2009, 6:48pm UTC](https://www.ruby-forum.com/t/cut-off-text-if-its-too-big-for-a-table-resize-table/162200/1 "2009-03-06T18:48:21Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![enchanter](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/ce7236/32.png) [@enchanter](https://www.ruby-forum.com/u/enchanter)\
**Post date:** [March 6, 2009, 6:52pm UTC](https://www.ruby-forum.com/t/cut-off-text-if-its-too-big-for-a-table-resize-table/162200/2 "2009-03-06T18:52:27Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![enchanter](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/ce7236/32.png) [@enchanter](https://www.ruby-forum.com/u/enchanter)\
**Post date:** [March 6, 2009, 9:57pm UTC](https://www.ruby-forum.com/t/cut-off-text-if-its-too-big-for-a-table-resize-table/162200/3 "2009-03-06T21:57:16Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![enchanter](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/ce7236/32.png) [@enchanter](https://www.ruby-forum.com/u/enchanter)\
**Post date:** [March 6, 2009, 11:24pm UTC](https://www.ruby-forum.com/t/cut-off-text-if-its-too-big-for-a-table-resize-table/162200/4 "2009-03-06T23:24:14Z")

</div>

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.
