Devise - Skipping user confirmation in Development

南笙酒味 提交于 2019-12-12 15:11:49

问题


How do you skip user confirmation in development in devise.

I have set up the production environment to send emails with SendGrid, but now I have done that it won't let me log in.

Thanks for your time!


回答1:


create User in console:

user = User.create( 
  :first_name            => 'admin', 
  :last_name             => 'admin', 
  :email                 => 'foo...@email.com', 
  :password              => 'password1', 
  :password_confirmation => 'password1' 
).skip_confirmation! 
 # Devise :doc:
 # If you don't want confirmation to be sent on create, neither a code
 # to be generated, call skip_confirmation!

or in model:

 after_create :skip_conf!

  def skip_conf!
    self.confirm! if Rails.env.development?
  end



回答2:


Another way:

User.new(email: 'xx@xx.xx', password: '12345678').confirm!

BTW, you can skip :password_confirmation at all, because #confirm! skips validation if record does not persisted yet.



来源:https://stackoverflow.com/questions/21168996/devise-skipping-user-confirmation-in-development

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