我正在构建一个基于Sinatra的API,我看到了一些针对我的User模型的奇怪响应。每个响应都返回一个充满空值的集合。其他型号按预期返回。
irb(main):018:0> User
=> User(id: integer, email: string, username: string, created_at: datetime, updated_at: datetime)
irb(main):019:0> User.find(1)
D, [2014-01-31T18:31:38.488743 #50624] DEBUG -- : User Load (0.1ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? LIMIT 1 [["id", 1]]
=> #<User id: 1, email: "test@example.com", username: "tyler", created_at: "2014-01-30 01:55:16", updated_at: "2014-01-30 01:55:16">
irb(main):020:0> User.find(1).to_json
D, [2014-01-31T18:32:18.079096 #50624] DEBUG -- : User Load (0.1ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? LIMIT 1 [["id", 1]]
=> "{\"id\":null,\"email\":null,\"username\":null,\"created_at\":null,\"updated_at\":null}"
答案 0 :(得分:1)
忘了我在User模型上有属性访问器方法。调整后,我得到了我期望的值。