简体   繁体   English

Rails:登录/注册后重定向回上一页

[英]Rails: redirect back to previous page after sign in / sign up

I am using Rails and devise for user authentication, I don't know how to redirect the user back to the previous page after successful sign in/sign up. 我正在使用Rails并设计用于用户身份验证,我不知道在成功登录/注册后如何将用户重定向到上一页。

I know about after_sign_in_path_for , but I don't know what I should write inside. 我知道after_sign_in_path_for ,但是我不知道该写些什么。

You can write custom sessions controller for devise login and use request.referrer to get the URL of the page the user is coming from. 您可以编写用于设计登录的自定义会话控制器 ,并使用request.referrer获取用户所在页面的URL。 Then just redirect back to the previous page after login. 登录后,只需重定向回上一页即可。 Also refer this doc . 另请参阅此文档 You could go by one of the methods. 您可以采用其中一种方法。 Hope it helps. 希望能帮助到你。

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

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