Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Devise gem skip confirmation and skip confirmation via email both at once

I am using devise gem and while creating user I want to skip confimation! and skip confimation email for example:

User.create(:first_name => "vidur", :last_name => "punj").confirm!.skip_confirmation!

But it skips only confirmation and doesn't skip sending confirmation email. Can any one give me an idea to skip both.

like image 458
vidur punj Avatar asked Dec 11 '12 10:12

vidur punj


5 Answers

You need to call skip_confirmation! before you save the record.

Try

user = User.new(:first_name => "blah")
user.skip_confirmation!
user.save
like image 76
Jamsi Avatar answered Oct 20 '22 03:10

Jamsi


If you are confused where to write skip_confirmation! method in controller as you have not generated devise controllers yet then:

Write this in your User model

before_create :my_method

def my_method
 self.skip_confirmation!
end

Now simply use:

user = User.new(:first_name => "Gagan")
user.save
like image 45
Gagan Gami Avatar answered Sep 30 '22 08:09

Gagan Gami


You are calling User.create before skip_confirmation!, you need to call User.new and user.save later.

Try

  user = User.new(:first_name => "vidur", :last_name => "punj")
  user.skip_confirmation!
  user.save! 
like image 5
SG 86 Avatar answered Oct 20 '22 03:10

SG 86


Got the solution:
 @user=User.new(:first_name => "vidur", :last_name => "punj")
 @user.skip_confirmation!
 @user.confirm!
 @user.save
like image 4
vidur punj Avatar answered Oct 20 '22 03:10

vidur punj


set the confirmed_at field

User.create!(confirmed_at: Time.now, email: '[email protected]', ...)

useful in seeds.rb

User.create_with(name: "Mr T", company: "Comp X", password: 'rubyrubyruby', password_confirmation: 'rubyrubyruby', confirmed_at: Time.now).find_or_create_by!( email: '[email protected]')
like image 4
oma Avatar answered Oct 20 '22 04:10

oma