Created
August 8, 2013 17:07
-
-
Save djbender/6186541 to your computer and use it in GitHub Desktop.
An admin user can skip validations for password when modifying another account.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class User < ActiveRecord::Base | |
cattr_accessible :admin_account | |
validates :password, unless: admin_account | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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