How to skip the need to confirm an email address update with devise?
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.
You can use this kind of code in your model # models/users.rb
. This will disable email reconfirmation on update:
def postpone_email_change?
false
end
or in your controller
def update
user.email = params[:user][:email]
user.skip_confirmation_notification!
if user.save
user.confirm
end
end