Rails 5 model objects not showing all Devise attributes

前端 未结 3 865
天命终不由人
天命终不由人 2021-01-18 06:53

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   \         


        
3条回答
  •  梦谈多话
    2021-01-18 07:07

    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.
    

提交回复
热议问题