Skip to content

Instantly share code, notes, and snippets.

@djbender
Created August 8, 2013 17:07
Show Gist options
  • Save djbender/6186541 to your computer and use it in GitHub Desktop.
Save djbender/6186541 to your computer and use it in GitHub Desktop.
An admin user can skip validations for password when modifying another account.
class User < ActiveRecord::Base
cattr_accessible :admin_account
validates :password, unless: admin_account
end
class UsersController < ActiveController
# If current_user is an admin make :admin_account the current user
User.admin_account = current_user if current_user != @user && current_user.admin?
#We create an attribute called admin_account then require password if admin_account is nil.
#In the controller we set the admin_account to current_user if current_user is an admin and they are editing someone else's account.
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment