简体   繁体   English

如何使 Rails devise 发布到 return_to 路径,而不是重定向到它?

[英]How to make Rails devise post to the return_to path, not redirect to it?

I'm using devise on rails 2.3 and need to have a form that is available both public and private - for logged in users and those who are not logged in. Both users should see it, but only logged in users can post the form.我在 rails 2.3 上使用 devise 并且需要有一个公共和私人可用的表单 - 用于登录用户和未登录用户。两个用户都应该看到它,但只有登录用户可以发布表单。

I would like to achieve that when an anonymous user has filled it and posts the form, then devise shows him the login page, he logs in and the contents of the form are posted.我想实现当匿名用户填写并发布表单时,devise 会向他显示登录页面,他登录并发布表单的内容。

Right now when I make the create action (to which the form posts itself) private, then devise would show him the login screen and remember where he came from - save the url to session[:return_to] and it redirects him back to the form.现在,当我将创建操作(表单向其发布)设为私有时,devise 会向他显示登录屏幕并记住他来自哪里 - 将 url 保存到 session[:return_to] 并将他重定向回表单.

Is there some other way than monkeypatching devise to do that?除了monkeypatching devise 还有其他方法吗?

I believe that Devise you will not be able to get Devise to post to a location on a successful login without some hacking of Devise.我相信 Devise 您将无法让 Devise 发布到成功登录的位置,而无需对 Devise 进行一些黑客攻击。

However, since you are saving the url in the session, you could easily also save the post data in the session as well, then just check for it when you are redirected back.但是,由于您将 url 保存在 session 中,因此您也可以轻松地将发布数据保存在 session 中,然后在重定向回来时检查它。 Also make sure that you delete it from the session once it has been used.还要确保在使用后将其从 session 中删除。

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

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