I have created a new API using rails/edge and I'm using devise with the devise_token_auth which has generated me a user model.
My question is this, after migrating and adding new attributes to the User model how do I return this in the JSON response, currently being generated by devise_token_auth?
This is what you need to to in order to permit custom attributes for the Devise model (e.g User model)
class ApplicationController < ActionController::Base
before_action :configure_permitted_parameters, if: :devise_controller?
protected
def configure_permitted_parameters
# for user account creation i.e sign up
devise_parameter_sanitizer.permit(:sign_up, keys: [:first_name, :last_name])
# for user account update
# where bank_name and bank_account are nested attributes in the User model
devise_parameter_sanitizer.permit(:account_update, keys: [:first_name, :last_name, bank_attributes: [:bank_name, :bank_account]])
end
end
source of this solution
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With