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...


On Fri, Feb 13, 2009 at 9:22 PM, John Smith <
rails-mailing-l...@andreas-s.net> wrote:

>
> 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('/')
> --
> Posted via http://www.ruby-forum.com/.
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to