If you're using restful_authentication plugin, check out the method
called redirect_back_or_default. Even otherwise, I think thats what
you want. Its a simple short method, try getting your hands on it.
You can store this information in the session, and then in your login action you should check if session[:next_page] is present, redirect user to that page; else to normal home page.