Ruby on Rails 3 - to_json not including all attributes

Viewed 3275

I'm using the to_json method on my model object that I created by doing something like:

user = User.find(1)

When I do user.to_json, a lot of attributes are missing, including user.id from the encoded JSON string. It appears that all of the attributes that I've added as attr_accessible from the User model are there, but none of the others. Perhaps that is what to_json is doing, but I think that adding id to attr_accessible is a no go.

What is the right way of solving this problem?

UPDATE

This looks to be a specific issue with Devise. If I comment out the following from user.rb, everything works as expected:

devise :rememberable, :trackable, :token_authenticatable, :omniauthable

5 Answers
Related