I've been trying to seed users to test out my Rails site and ran into the issue that on saving the user, my setup would send out a confirmation email. Multiply that times 100 dummy users and you have a problem. Rails documentation and SO led me to skip_confirmation!
, along the following lines [0]:
user = User.new(:username => name, :email => email, :password => password)
user.skip_confirmation!
user.save
However, (surprise surprise) this still sent out an email with every save. How can I get Devise to stop doing this?
Devise's #skip_confirmation!
is misleading. It says "If you don't want confirmation to be sent on create, neither a code to be generated, call skip_confirmation!."
Really what I was looking for in this case was #skip_confirmation_notification!
. The documentation makes the distinction that this "Skips sending the confirmation/reconfirmation notification email after_create/after_update."
This works! To get the above code to not send out a confirmation email, it should look like this:
user = User.new(:username => name, :email => email, :password => password)
user.skip_confirmation_notification!
user.save
You could also simply remove :confirmable
from the code below in your user.rb file
devise :database_authenticatable, :registerable, :recoverable, :rememberable, :trackable, :validatable, :confirmable, :async
In your test environment ActionMailer::Base.delivery_method
should be set to :test
, which means that these emails will not be sent out.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.