Skip to content

Instantly share code, notes, and snippets.

@strukturedkaos
Created October 9, 2012 13:16
Show Gist options
  • Save strukturedkaos/3858746 to your computer and use it in GitHub Desktop.
Save strukturedkaos/3858746 to your computer and use it in GitHub Desktop.
Seeding from CSV File Example
require 'csv'
seed_data_path = "db/seed/"
puts "Importing shifts..."
CSV.foreach(Rails.root.join(seed_data_path + "shifts.csv"), headers: true) do |row|
%w(Monday Tuesday Wednesday Thursday Friday Saturday Sunday).each do |day|
Shift.find_or_create_by_day_and_start_time_and_end_time(day, Time.parse(row[0]), Time.parse(row[1]))
end
end
start_time end_time
00:00 UTC 03:00 UTC
03:00 UTC 06:00 UTC
06:00 UTC 09:00 UTC
09:00 UTC 12:00 UTC
12:00 UTC 15:00 UTC
15:00 UTC 18:00 UTC
18:00 UTC 21:00 UTC
21:00 UTC 00:00 UTC
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment