Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Editing devise users requires password field to be filled in #495

Closed
chrisedington opened this issue Mar 1, 2016 · 8 comments
Closed

Editing devise users requires password field to be filled in #495

chrisedington opened this issue Mar 1, 2016 · 8 comments

Comments

@chrisedington
Copy link

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?

@OddEssay
Copy link

OddEssay commented Mar 3, 2016

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.

@sivicencio
Copy link

@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.

@rmcsharry
Copy link

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

@michelegera
Copy link

@sivicencio’s 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

@carlosramireziii
Copy link
Collaborator

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

@chrisedington
Copy link
Author

@carlosramireziii yeah the suggestion from @michelegera solved it.

@IJustDev
Copy link

Thank you very much for sharing. I think a lot of Rails projects utilize Devise for their authentication.

This code snippet should be documented in the Readme or at least be mentioned in some side note.

@sivicencio’s 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

@pablobm
Copy link
Collaborator

pablobm commented Jul 21, 2022

@IJustDev - That's a good point. I have added it to the list of things to document at #1778

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants