[英]How to redirect to the same url in 'after_update_path_for' with devise ruby on rails
更新密码后,我想重定向到同一页面。 我有两种看法:
edit.html.haml
(account_path)
edit_password.html.haml
(account_change_password_path)
当我更新帐户(edit或edit_password)时,它会将我重定向到根页面(我想重定向到同一页面)。
当我尝试在edit_password视图中更改密码(有错误)时,它会向我显示“编辑视图”中的设计错误(它应该向我显示edit_password视图中的设计错误)。
我试图用以下方法解决此问题:
class RegistrationsController < Devise::RegistrationsController
# ...
protected
def after_update_path_for(resource)
redirect_to :back
end
end
但它不起作用。
如何使其重定向到相同的URL?
您几乎完全正确。 因此,那些设计路径的助手after_sign_up_path
, after_sign_in_path
, after_update_path
都期望一个URL,特别是一个字符串。
对于其他访问此页面的人:更新后进行制作的关键是:
protected
部分中添加after_update_path
方法 例如,如果您想重定向回到您来自的页面:
class RegistrationsController < Devise::RegistrationsController
# ...
protected
def after_update_path_for(resource)
request.referrer || edit_user_registration_path
end
end
因此,如果用户位于edit_password_path上,它将把他们带回到那里。 但是,如果安全良心用户具有防病毒软件或不遵循软件,但该软件会将其引荐来源网址从其浏览器中删除,则您的备用方法是将用户带到完整的注册路径。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.