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.
You need to call skip_confirmation! before you save the record.
Try
user = User.new(:first_name => "blah")
user.skip_confirmation!
user.save
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
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!
Got the solution:
@user=User.new(:first_name => "vidur", :last_name => "punj")
@user.skip_confirmation!
@user.confirm!
@user.save
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]')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With