Question

I'm building a Sinatra-based API and I'm seeing some weird responses for my User model. Every response returns a collection full of null values. Other models return as expected.

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}"
Was it helpful?

Solution

Forgot I had attribute accessor methods on the User model. After adjusting those, I'm getting the values I expected.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top