繁体   English   中英

通过Devise发送重置密码说明后,我不想重定向

[英]I don't want to redirect after sending reset password instructions with Devise

发送重设密码说明时,我只需要显示一条消息,不需要重定向到新会话,就覆盖了controllerPassword,但是当我将redirect_to放置时,此呈现出现错误。

发送重置密码说明后使用的路径

def after_sending_reset_password_instructions_path_for(resource_name)
  flash[:notice] = "We have sent an email with the instructions to reset your password"
  redirect_to new_user_password_path and return
end

这是错误:此操作多次调用了渲染和/或重定向……

我该如何解决?

如果您删除redirect_to new_user_password_path and return从代码中完全redirect_to new_user_password_path and return ,它将停止重定向。 但是,如果执行此操作,则在用户手动刷新页面之前,它不会显示您的闪动通知。 从这里有两个修复程序:

  • 重定向到当前页面以强制刷新并显示通知。
  • 将您的Flash通知绑定到AJAX请求,以便异步发送。 有很多方法可以做到这一点,但是这个答案很好地覆盖了它。

调用after_sending_reset_password_instructions_path_for的控制器操作具有renderredirect_to

尝试在after_sending_reset_password_instructions_path_for删除redirect_to ,然后由调用操作对其进行处理。

我必须覆盖另一个名为的类:SessionsController <Devise :: SessionsController我不知道这是否是最好的解决方案,但对我有用。

这是我做的:

class SessionsController < Devise::SessionsController
  # GET /resource/sign_in
  def new
    url = (request.env["HTTP_REFERER"]).to_s
    path = url.split("?").first

    if path == "http://#{Rails.application.secrets.domain_name}/users/password/new"
      redirect_to new_user_password_path and return
    end

    self.resource = resource_class.new(sign_in_params)
    clean_up_passwords(resource)
    yield resource if block_given?
    respond_with(resource, serialize_options(resource))
  end

end

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM