Skip email confirmation when creating a new user using Devise

泪湿孤枕 提交于 2019-12-12 10:38:06

问题


I have a user registration page and will send the information to couple of admin users that one new user registered in the site.

Now, I created the seed data with list of users (200+). So, It'll send the 200+ email to the respective admin users. Hence, I want to stop send the mail confirmation to admin users when creating new user.


回答1:


For Devise, add user.skip_confirmation! before saving.

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

Cite: https://github.com/plataformatec/devise/pull/2296




回答2:


Another option is to do something like

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

In that way, you instantiate the object, skip the confirmation and save it in one step and return it to the user variable.

It's just another way to do the same in one step.



来源:https://stackoverflow.com/questions/20798573/skip-email-confirmation-when-creating-a-new-user-using-devise

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!