Skip to content

Instantly share code, notes, and snippets.

@MarkBennett
Created February 13, 2011 01:28
Show Gist options
  • Save MarkBennett/824319 to your computer and use it in GitHub Desktop.
Save MarkBennett/824319 to your computer and use it in GitHub Desktop.
Simple CSV importer
module PublisherImporter
extend self
# Import a csv given it's full path
def import(csv_path)
CSV.foreach(csv_path, :headers => true) do |row|
import_row(row)
end
end
def import_row(row)
publisher = Publisher.find_or_create_by_abbrev(row["Abbrev"].upcase)
publisher.name = row["Name"]
publisher.save!
publisher
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment