Help with return_back

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:
      redirect_back_or_default('/')

Based on the principle of least surprise, you’ve got two cases you need to plan for:

  1. The user explicitly requests the login page, and so after a successful 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 session variable based on these
    rules and depending on whether you get to your login page from a before
    filter method (classic name here in every example ever written is
    “authorize”) or from an HTTP GET request for your login page. In
    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…