Customs fields for Devise

Add extra fields post running initial migration

Posted by Nelson on January 27, 2021
I keep forgetting how to add extra fields like username or profile photo to devise on every install and then as usual I start trawling Stack Overflow for pre-2015 answers. So, here it is... 

On application_controller.rb make the following edit (in the example I have added four new fields to the User table: first_name, last_name, birth_date and profile_picture):


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

  protected
  def configure_permitted_parameters
    update_attrs = [:first_name, :last_name, :birth_date, :profile_picture]
    devise_parameter_sanitizer.permit(:account_update, keys: update_attrs)
  end
end