此代码给出以下错误:
def show_username(shipment)
userid = shipment.logs.last.user_id
User.find(userid).name
end
但是,如果我插入
byebug
我可以运行代码并访问所有变量和方法,而不会出现任何错误。
byebug公司
我得到以下回复:
(byebug) shipment.logs.last
Log Load (0.3ms) SELECT "logs".* FROM "logs" WHERE "logs"."shipment_id" = $1 ORDER BY "logs"."id" DESC LIMIT $2 [["shipment_id", 95], ["LIMIT", 1]]
#<Log id: 87, activity: "Shipment updated", created_at: "2017-08-28 15:19:07", updated_at: "2017-08-28 15:19:07", shipment_id: 95, user_id: 3>
(byebug) shipment.logs.last.user_id
Log Load (2.6ms) SELECT "logs".* FROM "logs" WHERE "logs"."shipment_id" = $1 ORDER BY "logs"."id" DESC LIMIT $2 [["shipment_id", 95], ["LIMIT", 1]]
3