ActiveAdmin: how to leave user password unchanged?

后端 未结 5 1561
天命终不由人
天命终不由人 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:52

    As told in comments on the @mauriceomdea answer, the def update is missing (or at least was missing for me, henerating an error.)

    Here is a more complete version that worked for me :

    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
    

    hope this helps someone.

提交回复
热议问题