简体   繁体   English

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

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

I need only show a message when send the reset password instructions, I don't need redirect to new session, I overwritten the controllerPassword but when I put a redirect_to there is a error with this render. 发送重设密码说明时,我只需要显示一条消息,不需要重定向到新会话,就覆盖了controllerPassword,但是当我将redirect_to放置时,此呈现出现错误。

The path used after sending reset password instructions 发送重置密码说明后使用的路径

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

this is the error: Render and/or redirect were called multiple times in this action...... 这是错误:此操作多次调用了渲染和/或重定向……

How can I fix it? 我该如何解决?

If you remove redirect_to new_user_password_path and return from your code entirely it will stop redirecting. 如果您删除redirect_to new_user_password_path and return从代码中完全redirect_to new_user_password_path and return ,它将停止重定向。 However, if you do this it won't show your flash notice until the user manually refreshes the page. 但是,如果执行此操作,则在用户手动刷新页面之前,它不会显示您的闪动通知。 From here there are two fixes: 从这里有两个修复程序:

  • redirect to the current page to force a refresh and show the notice. 重定向到当前页面以强制刷新并显示通知。
  • bind your flash notice to an AJAX request so that it's sent asynchronously. 将您的Flash通知绑定到AJAX请求,以便异步发送。 There are a lot of ways to do that, but this answer covers it pretty well. 有很多方法可以做到这一点,但是这个答案很好地覆盖了它。

The controller action which is calling after_sending_reset_password_instructions_path_for has a render or a redirect_to . 调用after_sending_reset_password_instructions_path_for的控制器操作具有renderredirect_to

Try removing redirect_to in after_sending_reset_password_instructions_path_for , and let the calling action handle it. 尝试在after_sending_reset_password_instructions_path_for删除redirect_to ,然后由调用操作对其进行处理。

I have to overwrite other class called: SessionsController < Devise::SessionsController I don't know if this is the best solution but worked for me. 我必须覆盖另一个名为的类:SessionsController <Devise :: SessionsController我不知道这是否是最好的解决方案,但对我有用。

This was I did: 这是我做的:

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