Devise - Skipping user confirmation in Development
Asked Answered
P

2

4

How do you skip user confirmation in development in devise.

I have set up the production environment to send emails with SendGrid, but now I have done that it won't let me log in.

Thanks for your time!

Phoenix answered 16/1, 2014 at 17:41 Comment(0)
I
9

create User in console:

user = User.create( 
  :first_name            => 'admin', 
  :last_name             => 'admin', 
  :email                 => '[email protected]', 
  :password              => 'password1', 
  :password_confirmation => 'password1' 
).skip_confirmation! 
 # Devise :doc:
 # If you don't want confirmation to be sent on create, neither a code
 # to be generated, call skip_confirmation!

or in model:

 after_create :skip_conf!

  def skip_conf!
    self.confirm! if Rails.env.development?
  end
Indomitability answered 16/1, 2014 at 17:49 Comment(2)
That's awesome, exactly what I was looking for! Clean and easy ;)Kollwitz
Thanks! For some reason I had to use just .confirm not .confirm!.Choker
P
2

Another way:

User.new(email: '[email protected]', password: '12345678').confirm!

BTW, you can skip :password_confirmation at all, because #confirm! skips validation if record does not persisted yet.

Petra answered 24/4, 2014 at 18:13 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.