Rails - 更新电子邮件给Devise用户

时间:2017-08-29 14:50:09

标签: ruby-on-rails devise

我有以下profile_controller的动作:

def update
  updated = if _profile_params[:password].present?
    current_user.skip_confirmation!
    current_user.update_with_password(_profile_params)
  else
    current_user.skip_confirmation!
    current_user.update(_profile_params)
  end

  if updated
    render json: ProfilePresenter::Public.new(current_user)
  else
    render status: :unprocessable_entity,
         json: Oj.dump({ errors: current_user.errors.messages })
  end
end

如果我向控制器发送以下有效负载:

{"first_name":"Aieie", "phone": "+393345678909", "email": "example@gmail.com"}

系统会生成确认电子邮件,即使我使用skip_confirmation!跳过它。

如何避免系统发送确认电子邮件?

2 个答案:

答案 0 :(得分:1)

在更新时和保存之前调用它时,您需要执行以下操作:

current_user.skip_reconfirmation!

记住skip_reconfirmation!

答案 1 :(得分:0)

好的,这很简单。只需使用.skip_reconfirmation!doc

即可