Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Skip email confirmation when creating a new user using Devise

I have a user registration page and will send the information to couple of admin users that one new user registered in the site.

Now, I created the seed data with list of users (200+). So, It'll send the 200+ email to the respective admin users. Hence, I want to stop send the mail confirmation to admin users when creating new user.

like image 438
Mr. Black Avatar asked Dec 27 '13 09:12

Mr. Black


2 Answers

For Devise, add user.skip_confirmation! before saving.

user = User.new(
    :email => '[email protected]',
    :password => 'password1',
    :password_confirmation => 'password1'
  )
user.skip_confirmation!
user.save!

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

like image 140
scarver2 Avatar answered Nov 06 '22 23:11

scarver2


Another option is to do something like

user = User.new.tap do |u|
  u.email = '[email protected]'
  u.password = 'hackme!'
  u.password_confirmation = 'hackme!'
  u.skip_confirmation!
  u.save!
end

In that way, you instantiate the object, skip the confirmation and save it in one step and return it to the user variable.

It's just another way to do the same in one step.

like image 42
DavidSilveira Avatar answered Nov 06 '22 22:11

DavidSilveira