Created
May 14, 2015 06:46
-
-
Save novikserg/34e2a3af12281d651460 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This file should contain all the record creation needed to seed the database with its default values. | |
# The data can then be loaded with the rake db:seed (or created alongside the db with db:setup). | |
# | |
# Examples: | |
# | |
# cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }]) | |
# Mayor.create(name: 'Emanuel', city: cities.first) | |
xlsx = Roo::Spreadsheet.open('db/xlsx/zipcodes.xlsx') | |
sheet = xlsx.sheet(0) | |
header = sheet.row(1) | |
((sheet.first_row + 1)..sheet.last_row).each do |row_index| | |
row = sheet.row(row_index) | |
result = {} | |
row.each_with_index do |cell, index| | |
field_name = header[index] | |
result[field_name] = cell | |
end | |
Zipcode.create(result) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment