0

I am using Devise, and in rails c when I type User.last then it only shows id, created_at, updated_at, and email even though there are many attributes than that. Why does it do this? Do I have control on which default attributes it can show?

Strawberry
  • 66,024
  • 56
  • 149
  • 197

1 Answers1

3

Security feature for not sharing critical information through API call and you can control it.

# app/models/user.rb

class User < ApplicationRecord

   devise :database_authenticatable,...

   ...

   protected

   def serializable_hash(options = nil) 
    super(options).merge(reset_password_token) # you can keep adding attributes here that you wish to expose
  end

end

And you can get a list of all attributes with :

User.new.attributes

Full answer from another similar question : https://stackoverflow.com/a/41754974/7970365

D1ceWard
  • 972
  • 8
  • 17