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?
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.