# How can I save the destination url with all the parameters?

**URL:** <https://www.ruby-forum.com/t/how-can-i-save-the-destination-url-with-all-the-parameters/160383>\
**Category:** Rails\
**Created:** [February 15, 2009, 6:12pm UTC](https://www.ruby-forum.com/t/how-can-i-save-the-destination-url-with-all-the-parameters/160383 "2009-02-15T18:12:02Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![captaffy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/f04885/32.png) [@captaffy](https://www.ruby-forum.com/u/captaffy)\
**Post date:** [February 15, 2009, 6:12pm UTC](https://www.ruby-forum.com/t/how-can-i-save-the-destination-url-with-all-the-parameters/160383/1 "2009-02-15T18:12:02Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![captaffy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/f04885/32.png) [@captaffy](https://www.ruby-forum.com/u/captaffy)\
**Post date:** [February 16, 2009, 5:51am UTC](https://www.ruby-forum.com/t/how-can-i-save-the-destination-url-with-all-the-parameters/160383/2 "2009-02-16T05:51:31Z")

</div>

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 S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
