[英]How to redirect the user to login page after sending password reset instructions in rails 3 using 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
,它将停止重定向。 但是,如果执行此操作,则在用户手动刷新页面之前,它不会显示您的闪动通知。 从这里有两个修复程序:
调用after_sending_reset_password_instructions_path_for
的控制器操作具有render
或redirect_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.