Reputation: 161
I have added a custom method to my (Devise) User controller:
def confirm
@user = User.find(params[:id])
@user.skip_confirmation!
respond_to
if @user.save
//display success message
else
// display error message
end
end
end
When I try to confirm a user via that, the save fails and I have two errors in @user.errors: password and password_confirm
Even in the rails console, if I try
@user.skip_confirmation!
@save
I get a rollback and the save fails.
Any ideas would be appreciated..
Additional Info
The problem causing this is the
validates_presence_of :password, :password_confirmation
in my User model. Even though a password and password confirmation was entered by the user on signup, those get hashed together to make the encrypted_password. For example, when I find a user in the console, the user has an encrypted_password, but no password or password_confirmation.
I have tried this
validates_presence_of :password, :password_confirmation, :on => :create
However it doesn't force the user to enter both a password and a confirm on the Change Password screen.
Any idea on how to get around this?
Upvotes: 0
Views: 337
Reputation: 6704
I think you're misunderstanding what skip_confirmation!
does.
Devise's confirmable
module will send a new user an e-mail with a link back to your app. Until they click that link, they'll be "unconfirmed" and unable to sign in. What skip_confirmation!
does is skip this workflow -- the user will be immediately confirmed, and can log in without first having to go through the e-mail confirmation flow.
You're getting the error you're getting because of validations on the user model. In particular, the user you're trying to save doesn't appear to have an existing password, so it's requiring a password
and matching password_confirmation
attribute.
I suspect that there's a better way to accomplish whatever your purpose is. Why isn't the normal confirmation workflow sufficient? What's this extra controller action trying to accomplish?
Upvotes: 1
Reputation: 1534
I think skip_confirmation!
actually does the saving.
What you want to check is probably if @user.persisted?
Upvotes: 0