Last Updated: April 14, 2019
·
7.277K
· jandudulski

Edit user without password in active admin

Add this to your admin resource:

controller do
  def update_resource(object, attributes)
    update_method = attributes.first[:password].present? ? :update_attributes : :update_without_password
    object.send(update_method, *attributes)
  end
end

4 Responses
Add your response

thanks for sharing!
there is also nice solution: http://stackoverflow.com/a/11676957/1171144

controller do
  def update_resource object, attributes
    attributes.each do |attr|
      if attr[:password].blank? and attr[:password_confirmation].blank?
        attr.delete :password
        attr.delete :password_confirmation
      end
    end

    object.send :update_attributes, *attributes
  end
end
over 1 year ago ·

I find this cleaner,
controller do def update if params[:user][:password].blank? params[:user].delete("password") end super end end </code>

over 1 year ago ·

I think Jan's solution works great with devise.

over 1 year ago ·

Great, thanks

over 1 year ago ·