Devise 3 (rails 4) can't update user without password

前端 未结 7 1099
萌比男神i
萌比男神i 2021-02-06 00:34

I\'m trying to update a user without having to provide a password, but approaches that worked on older devise/rails versions no longer work with devise 3 and rails 4 strong para

7条回答
  •  [愿得一人]
    2021-02-06 01:21

    simply override the Devise by creating app/controller/registrations_controller.rb

    class RegistrationsController < Devise::RegistrationsController
    
      protected
      def update_resource(resource, params)
        resource.update(params.except(:current_password))
      end
    end
    

    this code will directly update user params except :current_password

    and update config/routes.rb

    devise_for :users, controllers: {registrations: 'registrations'}
    

提交回复
热议问题