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!
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!
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With