首页 > 解决方案 > Created_at nil 即使在成功创建后

问题描述

我正在构建一个跟踪应用程序,当我尝试在我的 Rails 控制台上创建新的跟踪时遇到了一个奇怪的问题。

首先,它创建并且可以保存“created_at”值,但是当我放置“Tracking.last”之后,它根本没有“created_at”。

irb(main):005:0> Tracking.create(latitude: 1241214, longitude: 12421412, comment: "testing")

(0.2ms)  BEGIN

Tracking Create (0.4ms)  INSERT INTO "trackings" ("comment", "created_at", "updated_at", "longitude", "latitude") VALUES ($1, 
$2, $3, $4, $5) RETURNING "id"  [["comment", "testing"], 
["created_at", "2019-06-13 18:14:57.019001"], ["updated_at", 
"2019-06-13 18:14:57.019001"], ["longitude", 12421412.0], 
["latitude", 1241214.0]]

(0.5ms)  COMMIT

=> #<Tracking id: 3, comment: "testing", created_at: "2019-06-13 
21:14:57", updated_at: "2019-06-13 21:14:57", longitude: 
12421412.0, latitude: 1241214.0>

irb(main):006:0> Tracking.last

Tracking Load (0.5ms)  SELECT  "trackings".* FROM "trackings" 
ORDER BY "trackings"."id" DESC LIMIT $1  [["LIMIT", 1]]
=> #<Tracking id: 3, comment: "testing", created_at: nil, 
updated_at: nil, longitude: 12421412.0, latitude: 1241214.0>

我在这里想念什么?

标签: ruby-on-rails

解决方案


推荐阅读