0

I have a table with a title column on my index.html.erb. These titles are very long so when I render my page the table goes quite far horizontally across the screen. It's all on one line as well. How do I set it so that after around 6 words it goes onto another line, and after 6 more words the string is cut off. The table is looped! The full description can be read when a user visits the seperate show.html page

Some of the code below

<td class="px-6 py-4 whitespace-no-wrap border-b border-gray-200">
   <div class="text-sm leading-5 text-gray-900"><%= article.title %></div>
</td>
  • Characters is a much better cut off than words and will create greater consistency in the rendering. e.g. `"As one who enjoys long words"` vs `"Hippopotomonstrosesquipedaliophobics vehemently abhor such sesquipedalian responses"` – engineersmnky Jun 01 '20 at 13:53

1 Answers1

1

I guess you could try counting the amount of characters that you want and limit by that, e.g

<%= truncate(title, length:10) %>

But if you need something very robust to support screen sizes etc I'm pretty sure css can help you CSS text-overflow in a table cell?

Joel Blum
  • 7,750
  • 10
  • 41
  • 60