Forum: Ruby on Rails Help with return_back

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
John S. (Guest)
on 2009-02-13 22:22
I have to log in my app, after the login I want to return back to the
page I was visiting just before the redirect to the login. Now, I have
this in my Sessions controller:
Chris K. (Guest)
on 2009-02-14 10:16
(Received via mailing list)
Based on the principle of least surprise, you've got two cases you need
plan for:

   1. The user explicitly requests the login page, and so after a
   login, you send him back to the page he came from.
   2. The user requests a protected action that requires login, so you
   redirect to the login page and then, after successful login, take him
to the
   originally-requested page.

To solve this, you need to store the after-login destination in a
variable based on these rules and depending on whether you get to your
page from a before filter method (classic name here in every example
written is "authorize") or from an HTTP GET request for your login page.
either case, if the user succeeds in logging in and the variable is set,
reset the session variable and redirect to that location.  Otherwise,
redirect to a default location.

Hope this helps...

On Fri, Feb 13, 2009 at 9:22 PM, John S. <
This topic is locked and can not be replied to.