ruby-on-rails - Rails - 更新发送给 Devise 用户的电子邮件

标签 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

如果我将以下有效负载放入 Controller :

{"first_name":"Aieie", "phone": "+393345678909", "email": "<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="adc8d5ccc0ddc1c8edcac0ccc4c183cec2c0" rel="noreferrer noopener nofollow">[email protected]</a>"}

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

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

最佳答案

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

current_user.skip_reconfirmation!

记住skip_reconfirmation!

关于ruby-on-rails - Rails - 更新发送给 Devise 用户的电子邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45942212/

相关文章:

java - 以跨平台方式维护 Mysql 数据库模式的最佳实践是什么?

ruby-on-rails - Rails 控制台 - 使用 image_tag 方法

devise - Rails 4 和 Devise - 通过 JSON API 进行用户注册

ruby-on-rails - Ruby on Rails : SSO implementation with LDAP using Devise gem

ruby-on-rails - 从发动机外部在可安装的发动机 rails 中使用设计

ruby-on-rails - 我可以在 Rails 中有一个名为 "Transaction"的模型吗?

ruby-on-rails - ruby rails :Is it possible to overload index method in ActionController?

ruby-on-rails - 为什么 Rails 会在同一 session 的每个请求中更改 Set-Cookie header

ruby-on-rails - Rails 3 - Oberserver - 无法使用设计 @current_user

ruby-on-rails-3 - 设计可记住的东西就是什么都不记得