【问题标题】:Skip email confirmation when creating a new user using Devise使用 Devise 创建新用户时跳过电子邮件确认
【发布时间】:2014-01-14 22:05:30
【问题描述】:

我有一个用户注册页面,并将信息发送给一位新用户在该站点注册的几个管理员用户。

现在,我使用用户列表 (200+) 创建了种子数据。因此,它会将 200 多封电子邮件发送给相应的管理员用户。因此,我想在创建新用户时停止向管理员用户发送邮件确认。

【问题讨论】:

  • 您是否使用 gem 进行身份验证?如果有,是哪一个?
  • 是的,我正在使用 Devise gem 进行身份验证。

标签: ruby-on-rails-3 email devise seed devise-confirmable


【解决方案1】:

对于设计,请在保存前添加user.skip_confirmation!

user = User.new(
    :email => 'person@example.com',
    :password => 'password1',
    :password_confirmation => 'password1'
  )
user.skip_confirmation!
user.save!

引用:https://github.com/plataformatec/devise/pull/2296

【讨论】:

    【解决方案2】:

    另一种选择是做类似的事情

    user = User.new.tap do |u|
      u.email = 'email@server.com'
      u.password = 'hackme!'
      u.password_confirmation = 'hackme!'
      u.skip_confirmation!
      u.save!
    end
    

    这样,您实例化对象,跳过确认并一步保存并将其返回给用户变量。

    这只是一步完成的另一种方式。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多