Administrate: Editing devise users requires password field to be filled in

Created on 1 Mar 2016  路  6Comments  路  Source: thoughtbot/administrate

Hi,

I'm looking for some advice on how to handle this situation.

I have my Devise users model loaded into Administrate, and I need to be able to edit user information without needing to change/fill their passwords.

The validation at the moment throws:

1 error prohibited this user from being saved:
Password can't be blank

Any ideas how I can overcome this?

Most helpful comment

@sivicencio鈥檚 solution can be further simplified if we remember that our UsersController inherits from Administrate::ApplicationController: we get rid of the blank password values, and call super.

def update
  if params[:user][:password].blank?
    params[:user].delete(:password)
    params[:user].delete(:password_confirmation)
  end
  super
end

All 6 comments

I got around this by removing the fields from the FORM_ATTRIBUTES array in app/dashboards/user_dashboard.rb and then we add the users using Devise Invitable if needed from the admin side of things.

@chriscapetown This is not an Administrate issue. It can be solved overriding the create action in your users controller, as Devise state:

def update
  if params[:user][:password].blank?
    params[:user].delete(:password)
    params[:user].delete(:password_confirmation)
  end
  if requested_resource.update(resource_params)
    redirect_to(
      [namespace, requested_resource],
      notice: translate_with_resource("update.success"),
    )
  else
    render :edit, locals: {
      page: Administrate::Page::Form.new(dashboard, requested_resource),
    }
  end
end

Hope it helps.

There are some 'same but different' ;) solutions to this problem here:
http://stackoverflow.com/questions/7083575/updating-user-attributes-without-requiring-password

@sivicencio鈥檚 solution can be further simplified if we remember that our UsersController inherits from Administrate::ApplicationController: we get rid of the blank password values, and call super.

def update
  if params[:user][:password].blank?
    params[:user].delete(:password)
    params[:user].delete(:password_confirmation)
  end
  super
end

Hey @chriscapetown! Did any of the solutions above help solve your issue?

@carlosramireziii yeah the suggestion from @michelegera solved it.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

conwayanderson picture conwayanderson  路  4Comments

gracewashere picture gracewashere  路  3Comments

Reedian picture Reedian  路  4Comments

drewtunney picture drewtunney  路  3Comments

ghost picture ghost  路  4Comments