Reputation: 25
I'm trying to permit :firstname when registering an account, but the params are not passed through, what am I doing wrong?
I have already migrated a :firstname string into the database
# protected
# If you have extra params to permit, append them to the sanitizer.
# def configure_sign_up_params
# devise_parameter_sanitizer.permit(:sign_up, keys: [:attribute, :firstname])
# end
# If you have extra params to permit, append them to the sanitizer.
# def configure_account_update_params
# devise_parameter_sanitizer.permit(:account_update, keys: [:attribute, :firstname])
# end
Upvotes: 1
Views: 429
Reputation: 710
You need to do couple things:
registrations controller
. You can do that with this command:rails g devise:controllers users -c=registrations
routes.rb
file, add this:devise_for :users, controllers: { registrations: 'users/registrations' }
registrations_controller.rb
permit the extra params:
class Users::RegistrationsController < Devise::RegistrationsController
before_action :configure_sign_up_params, only: [:create]
protected
# If you have extra params to permit, append them to the sanitizer.
def configure_sign_up_params
devise_parameter_sanitizer.permit(:sign_up, keys: [:firstname])
end
end
Reference:
https://github.com/plataformatec/devise/wiki/Tool:-Generate-and-customize-controllers
Upvotes: 2
Reputation: 1168
You already read this code, to do so you just need to uncomment configure_sign_up_params
method and add your attributes to the keys
, something like the code below.
# protected
# If you have extra params to permit, append them to the sanitizer.
def configure_sign_up_params
devise_parameter_sanitizer.permit(:sign_up, keys: [:firstname])
end
# If you have extra params to permit, append them to the sanitizer.
# def configure_account_update_params
# devise_parameter_sanitizer.permit(:account_update, keys: [:attribute, :firstname])
# end
Upvotes: 1
Reputation: 521
We may have get some problem while using sanitize
for custom attributes in devise. Please follow this Add Custom Attributes
.
Upvotes: 0