简体   繁体   中英

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.

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.

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.

Is there some other way than monkeypatching devise to do that?

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.

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. Also make sure that you delete it from the session once it has been used.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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