I want to send additional values when the user signs up and do some logic before creating the record using devise and devise-JWT in Rails API, I used that https://rubydoc.info/github/heartcombo/devise/main/Devise/ParameterSanitizer to permit additional parameters
choice is not a column in the User table.
application_controller
before_action :configure_permitted_parameters, if: :devise_controller?
protected
def configure_permitted_parameters
attributes = [:choice]
devise_parameter_sanitizer.permit(:sign_up, keys: attributes)
devise_parameter_sanitizer.permit(:account_update, keys: attributes)
end
ActionDispatch::Http::Parameters::ParseError (Error occurred while parsing request parameters):
CodePudding user response:
According to Devise documentation, you are able to generate custom Devise controllers, so you may put your own logic.
https://github.com/heartcombo/devise#getting-started
CodePudding user response:
In my case, I added an attribute named "current_client_aplication_id" to the params object for respective request. For knowing how do it, I had to inspect the params objct just in that line, using byebug for debuging.
#application_controller
before_action do
session[:current_client_application_id] = "1"
params[request["controller"].singularize]["client_application_id"] = session[:current_client_application_id] if params[request["controller"].singularize]
end
In this way, "current_client application_id" is available in all requests.