The way Devise does this (in broad terms) is that on any page where you check for authentication (before_action :authenticate_user!) that method first checks to see if you are already signed in, if not, it stores the location of the page where you are in a cookie, then redirects you to the new session path, if you are successful in authenticating, then the session create method removes your original destination from the cookie, and redirects you there.
Walter
> To view this discussion on the web visit
https://groups.google.com/d/msgid/rubyonrails-talk/6e81c04d-1d2d-4051-aea3-4595e46d752a%40googlegroups.com.