How do a I modify a standard scaffold table generator to do this

People,

I want to modify Rails so that the standard scaffold table generator produces tables that in the list view:

  1. Have column names that are clickable for sorting (asc, desc) and filterable

  2. Have rows with every second row having a light blue background colour

  3. Have rows that are only a single line high that look like this:

| ID | Title                                 | Year | Storyline | Notes     |
|  1 | Eternal Sunshine of the Spotless Mind | 2004 | Much . .  | Loved . . |
  • where the whole of one field is displayed but only the first word of the other fields is displayed but eg in the above case, the whole Storyline or Notes can be displayed by hovering the mouse over the field.

Of course I couldn’t find any starter apps on GitHub etc that already did this so any suggestions about how to do this for myself would be grealy appreciated . .

Thanks,

Phil.

  1. I’d suggest looking at the Ransack gem. It makes filtering and sorting pretty easy. If paired with Pagy for pagination you’ll have a pretty slick index page.

  2. You’ll need to do with your CSS

tr:nth-child(even) {
  background-color: #d1d9e6;
}

But if you really want to use ruby/rails to do the assign the classes to each row, you could use cycle to switch the rows CSS class.

<tr class="<%= cycle("bg-white", "bg-gray", name: "row_class") -%>">
  1. Can be done with your CSS as well, by controlling your elements overflow.
tr {
  overflow: hidden;
}
1 Like