How to add username field to devise gem?

前端 未结 5 1288
时光说笑
时光说笑 2020-12-14 23:40

Here is what I tried,

  1. rails g migration add_username_to_hrs

  2. bundle exec rake db:migrate

  3. added the

5条回答
  •  囚心锁ツ
    2020-12-15 00:20

    If you are using rails 4 then follow this steps:

    1. rails g migration AddUserNameToAuthorize

    2. rake db:migrate

    3. put this code in application_controller.rb to accept username parameter for sign_in, sign_up and also for account_update:

      class ApplicationController < ActionController::Base
          protect_from_forgery with: :exception
          def configure_permitted_parameters
            devise_parameter_sanitizer.for(:sign_in) { |u| u.permit(:email, :password,:username) }
            devise_parameter_sanitizer.for(:sign_up) { |u| u.permit(:email, :password, :password_confirmation,:username) }
            devise_parameter_sanitizer.for(:account_update) { |u| u.permit(:email, :password, :password_confirmation,:username) }
          end
      end
      

提交回复
热议问题