Skip confirmation email when creating a new user using the utility

I have a user registration page, and we will send the information to several admin users registered on the site as one new user.

Now I have created the initial data with a list of users (200+). Thus, it will send 200+ emails to the corresponding admin users. Therefore, I want to stop sending confirmation emails to admin users when creating a new user.

+6
source share
2 answers

For Devise add user.skip_confirmation! before saving.

 user = User.new( :email => ' person@example.com ', :password => 'password1', :password_confirmation => 'password1' ) user.skip_confirmation! user.save! 

Cite: https://github.com/plataformatec/devise/pull/2296

+12
source

Another option is to do something like

 user = User.new.tap do |u| u.email = ' email@server.com ' u.password = 'hackme!' u.password_confirmation = 'hackme!' u.skip_confirmation! u.save! end 

So you create an instance of the object, skip the confirmation and save it in one step and return it to the user variable.

This is just another way to do the same in one step.

+5
source

All Articles