Save the page when you go to login, then used that to return the user to that page after login, e.g.
# redirect to the login page. Call this in the login action, when successful.
def redirect_away(*params)
session[:original_uri] = request.request_uri
redirect_to(*params)
end
# returns to the original url from a redirect_away or to a default url
def redirect_back(*params)
uri = session[:original_uri]
session[:original_uri] = nil
if uri
redirect_to uri
else
redirect_to(*params)
end
end