Generated User model using Devise gem.
Trying to add 'username' attribute.
Followed official documentation, now my ApplicationController looks like this:
class ApplicationController < ActionController::Base
protect_from_forgery with: :exception
before_action :configure_permitted_parameters, if: :devise_controller?
before_action :authenticate_user!
protected
def configure_permitted_parameters
devise_parameter_sanitizer.permit(:account_update, keys: [:username])
devise_parameter_sanitizer.permit(:sign_in, keys: [:username])
devise_parameter_sanitizer.permit(:sign_up, keys: [:username])
end
end
When I try to go to account update page I get following error:
NoMethodError in Devise::RegistrationsController#edit
private method `permit' called for #Devise::ParameterSanitizer:0x007f13396cf180>
What can be wrong in here?
According to this answer, you can also do the following:
def configure_permitted_parameters
devise_parameter_sanitizer.for(:sign_in) << :username
devise_parameter_sanitizer.for(:sign_up) << :username
devise_parameter_sanitizer.for(:account_update) << :username
end
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