我的seeds.rb 文件中有以下代码:
# create a 7 day wall
for day in 1..7
# create the days
d = Day.create(day: day)
# for each day create the time slots. Use 15 minute timeslots for now
start_time = Time.new.beginning_of_day
puts start_time
end_time = start_time.end_of_day
puts end_time
begin
d.time_slots << TimeSlot.create(time: start_time)
start_time += 15.minutes
puts start_time
end while start_time <= end_time
puts "Start time after exit: #{start_time}"
campaign.days << d
end
它像人们期望的那样创建正确的输出
2013-04-19 00:00:00 -0700
2013-04-19 23:59:59 -0700
2013-04-19 00:15:00 -0700
2013-04-19 00:30:00 -0700
2013-04-19 00:45:00 -0700
2013-04-19 01:00:00 -0700
2013-04-19 01:15:00 -0700
2013-04-19 01:30:00 -0700
2013-04-19 01:45:00 -0700
2013-04-19 02:00:00 -0700
2013-04-19 02:15:00 -0700
2013-04-19 02:30:00 -0700
2013-04-19 02:45:00 -0700
2013-04-19 03:00:00 -0700
2013-04-19 03:15:00 -0700
2013-04-19 03:30:00 -0700
....
当我使用 sqlite 浏览器查看我的数据库时,我也看到了这一点。当使用我的 rails 控制台检查数据库时,我看到:
1.9.3p194 :001 > TimeSlot.find(1)
TimeSlot Load (17.3ms) SELECT "time_slots".* FROM "time_slots" WHERE "time_slots"."id" = ? LIMIT 1 [["id", 1]]
=> #<TimeSlot id: 1, time: "2000-01-01 07:00:00", created_at: "2013-04-19 21:56:58", updated_at: "2013-04-19 21:56:58", campaign_id: nil, day_id: 1>
为什么数据库中的记录显示错误的日期?时间戳是正确的,但时间字段是错误的。我不明白。