ActiveAdmin: how to leave user password unchanged?

后端 未结 5 1563
天命终不由人
天命终不由人 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条回答
  •  梦毁少年i
    2021-02-01 16:52

    Devise provides an update_without_password method that you can use when updating a user if no password is entered. Using that method, you can customize the update method in your ActiveAdmin users controller.

     def update
       @user = User.find(params[:id])
       if params[:user][:password].blank?
         @user.update_without_password(params[:user])
       else
         @user.update_attributes(params[:user])
       end
       if @user.errors.blank?
         redirect_to admin_users_path, :notice => "User updated successfully."
       else
         render :edit
       end
     end
    

    The Devise Wiki has more information about this method if your interested.

提交回复
热议问题