ActiveAdmin: how to leave user password unchanged?

后端 未结 5 1558
天命终不由人
天命终不由人 2021-02-01 16:27

I am using ActiveAdmin as my administration backend in my rails app. Basically, I have an admin_user and a user model.

When I create a new us

5条回答
  •  一生所求
    2021-02-01 16:31

    You don't really need to mess at all with Devise's registration controller, you can just ignore empty password fields inside ActiveAdmin's resource controller:

    ActiveAdmin.register User do
      controller do
    
        def update
          model = :user
    
          if params[model][:password].blank?
            %w(password password_confirmation).each { |p| params[model].delete(p) }
          end
    
          super
        end
      end
    end
    

提交回复
热议问题