Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to skip the need to confirm an email address update with devise?

I'm using rails with devise confirmable.

Generally I want to have users confirm their email address, however sometimes I need to manually change an email on behalf of an existing user and I want to skip sending the confirmation email.

When creating a new user I can skip the confirmation email with:

user.skip_confirmation! 

...but this does not appear to work for existing, already confirmed users - insofar as the email attribute is not updated, and devise still requires the user to confirm the new email and sends out a confirmation email:

@user = User.find_by_email('[email protected]') @user.email = '[email protected]' @user.skip_confirmation! @user.save! 
like image 929
AnApprentice Avatar asked Mar 19 '12 21:03

AnApprentice


2 Answers

The method you want to use is skip_reconfirmation! (note the 're' in reconfirmation).

@user = User.find_by_email('[email protected]') @user.email = '[email protected]' @user.skip_reconfirmation! @user.save! 
like image 154
RailinginDFW Avatar answered Sep 30 '22 17:09

RailinginDFW


Try setting Devise.reconfirmable or User.reconfirmable (or whatever your model is) to false. You can set it on config/initializers/devise.rb on this line:

# If true, requires any email changes to be confirmed (exctly the same way as # initial account confirmation) to be applied. Requires additional unconfirmed_email # db field (see migrations). Until confirmed new email is stored in # unconfirmed email column, and copied to email column on successful confirmation. config.reconfirmable = true 

You can also use Active Record's update_column method, which saves a field without running callbacks or validations.

like image 32
Rodrigo Flores Avatar answered Sep 30 '22 17:09

Rodrigo Flores