Unpermitted Parameters adding new fields to Devise in rails 4.0

后端 未结 7 1719
灰色年华
灰色年华 2020-12-02 09:26

Very new to working with rails. I have implemented a basic login system using Devise. I am trying to add a couple of new fields (bio:string, name:string) into the sign_up pa

7条回答
  •  误落风尘
    2020-12-02 09:47

    For both sign_up and account_update do this for controllers/applcation_controller.rb

    class ApplicationController < ActionController::Base
      protect_from_forgery with: :exception
      before_action :authenticate_user!
    
      before_action :configure_permitted_parameters, if: :devise_controller?
      protected
      def configure_permitted_parameters
        devise_parameter_sanitizer.for(:account_update) { |u| u.permit(:password, :password_confirmation,:current_password,:email,:name, :phonenumber,:province,:city,:area,:idcardimg,:role) }
        devise_parameter_sanitizer.for(:sign_up) { |u| u.permit(:password, :password_confirmation,:current_password,:email,:name, :phonenumber,:province,:city,:area,:idcardimg,:role) }
      end
    end
    

提交回复
热议问题