Rails 5 model objects not showing all Devise attributes

前端 未结 3 866
天命终不由人
天命终不由人 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:17

    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!

提交回复
热议问题