Tue, 13 Jul 2010 14:52:29 GMT

Import CSV files in Rails 3

CSV is a ubiquitous importing and exporting format for tables of information conforming to row-column layout. Lines correspond to rows. On each line, commas separate values under each column; hence Comma-Separated Values. Values between commas define table-cell contents, strings or numbers. The format is relatively flexible, relatively easy for machines and even humans to read and write.

In terms of user stories, it answers the following requirement.

As a: database maintainer

I want to: import information from external files, particularly Comma-Separated Value files where rows appear on each line and columns within each row have comma delimiters

So that I can: select columns (and rows) from the CSV files and merge these to create other new pieces of information.

Question is, How do you import CSV files in Rails 3. This article attempts an answer, or at least part of an answer, enough perhaps to point you in the right direction. You can find the sources here at GitHub.