I'm producing a CSV export (in ruby, from rails) of a variable number of records. The number of fields exported per record varies depending on how many authors each book has. This isn't ideal, given that the users are going to look at this CSV in something like Excel, and expect to see the data presented consistently in columns. How can I set the number of columns to be the total number of times the block gets iterated, given that the structure of the csv builder is something like this:
# header-row for the data
csv << ["column heading 1", "column heading 2", "column heading 3" #etc]
Book.all do |book|
row_data = book.id
row_data << book.some_other_field # etc
book.authors.each do |author|
row_data << author.first.name
#etc