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?
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.
Most helpful comment
@sivicencio鈥檚 solution can be further simplified if we remember that our
UsersControllerinherits fromAdministrate::ApplicationController: we get rid of the blankpasswordvalues, and callsuper.