Skip email confirmation when creating a new user using Devise
Asked Answered
N

2

7

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.

Notification answered 27/12, 2013 at 9:59 Comment(2)
Are you using a gem for authentication? If so, which one?Amanita
Yes, I'm using Devise gem for authentication.Notification
A
14

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

Amanita answered 30/12, 2013 at 13:0 Comment(0)
C
5

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.

Commode answered 27/7, 2014 at 16:17 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.