Last Updated: February 25, 2016
·
4.21K
· arnaudm

CSV: undefined method `encode' for nil:NilClass

If you are importing a legacy database through a CSV file (such as from a Microsoft Excel export) you may bump into this Exception.

It got me scratching my head until I realized that ::CSV was trying to tell me that my CSV header line had one column less than the data beneath it (and I was asking for header conversion).

Especially hard to see when the missing column header is the last one! In which case it was a simple matter of adding a ; to mark the missing, unused column.