模型没有在时间字段中正确保存

时间:2013-09-11 03:33:45

标签: ruby-on-rails ruby-on-rails-4

2.0.0-p247 :001 > EventDate
 => EventDate(id: integer, title: string, allDay: boolean, start: time, end: time, created_at: datetime, updated_at: datetime, event_id: integer)
2.0.0-p247 :002 > ex = EventDate.find(2)
  EventDate Load (8.4ms)  SELECT "event_dates".* FROM "event_dates" WHERE "event_dates"."id" = ? LIMIT 1  [["id", 2]]
 => #<EventDate id: 2, title: "Work all day", allDay: true, start: "2000-01-01 07:00:00", end: nil, created_at: "2013-09-10 09:02:06", updated_at: "2013-09-11 02:15:09", event_id: 1>
2.0.0-p247 :004 > ex.start = Time.local(2013, 9, 20)
 => 2013-09-20 00:00:00 -0700
2.0.0-p247 :005 > ex.save
   (0.1ms)  begin transaction
  SQL (2.0ms)  UPDATE "event_dates" SET "start" = ?, "updated_at" = ? WHERE "event_dates"."id" = 2  [["start", 2013-09-20 00:00:00 -0700], ["updated_at", Wed, 11 Sep 2013 03:26:39 UTC +00:00]]
   (0.6ms)  commit transaction
 => true
2.0.0-p247 :006 > ex
 => #<EventDate id: 2, title: "Work all day", allDay: true, start: "2013-09-20 00:00:00", end: nil, created_at: "2013-09-10 09:02:06", updated_at: "2013-09-11 03:26:39", event_id: 1>
2.0.0-p247 :007 > EventDate.find(2)
  EventDate Load (0.2ms)  SELECT "event_dates".* FROM "event_dates" WHERE "event_dates"."id" = ? LIMIT 1  [["id", 2]]
 => #<EventDate id: 2, title: "Work all day", allDay: true, start: "2000-01-01 07:00:00", end: nil, created_at: "2013-09-10 09:02:06", updated_at: "2013-09-11 03:26:39", event_id: 1>

这是我的rails控制台的输出。如果您按照代码,您将看到我更新了id = 2的EventDate的开始字段。我保存它,当我检索相同的元素时,它不反映更改。但是,更改像标题这样的字段可以正确保存。

0 个答案:

没有答案