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
Written by Jan Dudulski
Related protips
4 Responses
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
·
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Ruby
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#