![](/img/trans.png)
[英]Rails Devise and skip_confirmation!, how to avoid autologin
[英]How to get Devise in Rails skip_confirmation to actually not send an email?
我一直试图为用户提供种子以测试我的Rails站点,并遇到一个问题,即在保存用户时,我的设置会发送一封确认电子邮件。 将其乘以100个虚拟用户,您就会遇到问题。 Rails文档和SO导致我进行了skip_confirmation!
,按以下几行[0]:
user = User.new(:username => name, :email => email, :password => password)
user.skip_confirmation!
user.save
但是,(惊讶的是)每次保存时仍然会发送一封电子邮件。 如何让Devise停止这样做?
Devise的#skip_confirmation!
有误导性。 它说:“如果您不想在创建时发送确认,也不希望生成任何代码,请调用skip_confirmation!。”
在这种情况下,我真正要的是#skip_confirmation_notification!
。 该文档的区别在于此“跳过在after_create / after_update中发送确认/确认通知电子邮件”。
这可行! 为了使上面的代码不发送确认电子邮件,它应如下所示:
user = User.new(:username => name, :email => email, :password => password)
user.skip_confirmation_notification!
user.save
您还可以从user.rb文件中的以下代码中删除:confirmable
devise :database_authenticatable, :registerable, :recoverable, :rememberable, :trackable, :validatable, :confirmable, :async
在您的测试环境中, ActionMailer::Base.delivery_method
应该设置为:test
,这意味着这些电子邮件将不会发送出去。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.