Skip to content

Instantly share code, notes, and snippets.

@vparihar01
Created April 10, 2013 12:53
Show Gist options
  • Save vparihar01/5354340 to your computer and use it in GitHub Desktop.
Save vparihar01/5354340 to your computer and use it in GitHub Desktop.
Simple gist to read data from csv and populating data to database.
require "csv"
require "fileutilities"
csv_data = File.Read("#{Rails.public_path}/location_of_csv_inside_your_public_dir.csv")
csv = CSV.parse(csv_data,:headers => false)
csv.each do |row|
puts row.inspect
age = AgeGroup.find_by_name(row[2])
category = CategoryFlag.find_by_name(row[4]) if row[5] == "flag"
category = CategoryTackle.find_by_name(row[4]) if row[5] == "tackle"
Drill.create(:name => row[0], :age_group_id =>age.id,:category_id=>category.id,:game_type=>row[5],:file=>row[6])
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment