Rails 5, Undefined method `for' for #<Devise on line devise_parameter_sanitizer.for

According to the documentation:

The Parameter Sanitaizer API has changed for Devise 4

class ApplicationController < ActionController::Base
  before_action :configure_permitted_parameters, if: :devise_controller?

  protected

  def configure_permitted_parameters
    devise_parameter_sanitizer.permit(:sign_up, keys: [:username])
  end
end

If you just change the .for to .permit it works as well. For example:

devise_parameter_sanitizer.permit(:sign_up) { |u| u.permit({ roles: [] }, :email, :password, :password_confirmation, :username) }

It works in both Rails 4.2.x and Rails 5.0.x


Don't forget devise_parameter_sanitizer.permit(:account_update, keys: [:username])