Created
October 9, 2012 13:16
-
-
Save strukturedkaos/3858746 to your computer and use it in GitHub Desktop.
Seeding from CSV File Example
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' | |
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 |
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
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