简体   繁体   English

如何在Rails中使Devise skip_confirmation实际不发送电子邮件?

[英]How to get Devise in Rails skip_confirmation to actually not send an email?

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. 我一直试图为用户提供种子以测试我的Rails站点,并遇到一个问题,即在保存用户时,我的设置会发送一封确认电子邮件。 Multiply that times 100 dummy users and you have a problem. 将其乘以100个虚拟用户,您就会遇到问题。 Rails documentation and SO led me to skip_confirmation! Rails文档和SO导致我进行了skip_confirmation! , along the following lines [0]: ,按以下几行[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停止这样做?

[0] https://stackoverflow.com/a/8673771/4283301 [0] https://stackoverflow.com/a/8673771/4283301

Devise's #skip_confirmation! Devise的#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!." 它说:“如果您不想在创建时发送确认,也不希望生成任何代码,请调用skip_confirmation!。”

Really what I was looking for in this case was #skip_confirmation_notification! 在这种情况下,我真正要的是#skip_confirmation_notification! . The documentation makes the distinction that this "Skips sending the confirmation/reconfirmation notification email after_create/after_update." 该文档的区别在于此“跳过在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 您还可以从user.rb文件中的以下代码中删除:confirmable

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. 在您的测试环境中, ActionMailer::Base.delivery_method应该设置为:test ,这意味着这些电子邮件将不会发送出去。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM