Forum: Ruby on Rails How can I save the destination url with all the parameters?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
71e53b54803415f87ef1b898baf8f3ca?d=identicon&s=25 John Smith (terry_wolf)
on 2009-02-15 18:12
I want too save the destination url with all the parameters (like some
ids) in a variable session, so first I login the app and then redirect
to this destination. How can I save this variable?
0d56133042e4814c1b2255ea655f2361?d=identicon&s=25 Jeff Burlysystems (jburly)
on 2009-02-16 05:51
(Received via mailing list)
If I understand what you're asking, ....  In your controller when you
test whether a user is logged-in or not, if they aren't logged in,
you'll want to save their current request uri in their session so that
you can later redirect them to that orig destination once they've
successfully logged in.  Something like:

...
  # the place in your controller where you test logged-in-ness:
  if not is_user_logged_in
    session[:pre_login_req_uri] = request.env['REQUEST_URI']
    redirect_to(:action=>:login)
    return
  end
...

  # in your login meth, after the user has successfully logged-in:
  pre_login_uri = session[:pre_login_req_uri]
  session[:pre_login_req_uri] = nil
  if pre_login_req_uri
    redirect_to(pre_login_req_uri)
  else
    redirect_to(:action=>:index)
  end
  return
...

Jeff

On Feb 15, 9:12 am, John Smith <rails-mailing-l...@andreas-s.net>
This topic is locked and can not be replied to.