Topic: Scaffold CSS to make multiple columns

Hi Everyone,

I built a scaffold and I'm having trouble getting results properly formatted. I'm not sure if the problem lies in scaffold.css, layout/books.rhtml, or the books/index.rhtml.erb Anyways, here is the default scaffold view:

Title           Abstract
Book One     Book One Abstract        Show     Edit     Destroy
Book Two     Book Two Abstract        Show      Edit    Destroy
Book Three   Book Three Abstract      Show      Edit    Destroy


I've tried editing scaffold.css, layouts/books.rhtml.erb, and books/index.rhtml.erb but can only achieve this result:

Book One                   
Book One Abstract           
Show Edit Destroy           
Book Two
Book Two Abstract
Show Edit Destroy
Book Three
Booth Three Abstract
Show Edit Destroy

This is the view I would like to see:

Book One                         Book Two                     Book Three
Book One Abstract           Book Two Abstract         Book Three Abstract
Show Edit Destroy           Show Edit Destroy         Show Edit Destroy

Does the problem lie elsewhere? Perhaps in books_controller.rb? Thanks for your help!

Re: Scaffold CSS to make multiple columns

What you're trying to do is to make a row-based table into a column-based table.

Your problem is that the HTML in tables is written row-by-row, not column-by-column, and so when you iterate over the database rows and write them into your HTML table one by one the result is going to be a row-by-row table.

What you can do is go to the controller, pull all of your data out of the database and into an array, then in your view you iterate over that array by COLUMN (so index [0][0], then, [1][0] then [2][0], then [0][1], then [1][1], then [2][1], etc.). Every time you reach a new row, write a <tr> and every time you reach a new column, write a <td>. This will effectively transpose the table, turning rows into columns.

Re: Scaffold CSS to make multiple columns

Another option, similar to Milosz, is something like this (untested):

    <% @books.each do |book| %>
        <%= %><br/>
        <%= book.abstract %><br/>
        # show, edit, destroy links
    <% end %>

This may be a little easier to visualize and doesn't require an additional array but doesn't display its data in a truly tabular format.