I am using Rails 5 API with devise. I have a User
model. Schema looks like this.
create_table \"users\", force: :cascade do |t|
t.string \
This is probably because devise
does not expose their internal attributes.
So to get all attributes you can use .attributes
(documented here) which returns a hash, on which you can call to_json
:
user = User.find(1)
user.attributes.to_json # => contains all fields like reset_password_token etc.
Try attributes
method
User.first.attributes
Devise restricts attributes like encrypted_password
so that the critical information doesn't get exposed in API calls. So to override this, you need to override serializable_hash
method.
def serializable_hash(options = nil)
super(options).merge(encrypted_password: encrypted_password)
end
This is not a Rails 5 specific feature but a Devise feature to protect your attributes.
Hope that helps!