Created
April 10, 2013 12:53
-
-
Save vparihar01/5354340 to your computer and use it in GitHub Desktop.
Simple gist to read data from csv and populating data to database.
This file contains hidden or 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
| 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