# Page redirect

**URL:** <https://www.ruby-forum.com/t/page-redirect/176423>\
**Category:** Ruby\
**Created:** [September 30, 2009, 11:13am UTC](https://www.ruby-forum.com/t/page-redirect/176423 "2009-09-30T11:13:14Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![sharankruthi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/97f17d/32.png) [@sharankruthi](https://www.ruby-forum.com/u/sharankruthi)\
**Post date:** [September 30, 2009, 11:13am UTC](https://www.ruby-forum.com/t/page-redirect/176423/1 "2009-09-30T11:13:14Z")

</div>

Hi,

In my application, if someone enters url which requires login, am  
redirecting to login page if they have not logged in already, after  
logging, i want to take the user to page from where he has been  
redirected to login page. how it can be done?

example : questions/new -\> redirected to login  
after logging, redirect user to questions/new

How to do?

Thankx in advance

---

<div class="post-metadata">

**Author:** ![sharankruthi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/97f17d/32.png) [@sharankruthi](https://www.ruby-forum.com/u/sharankruthi)\
**Post date:** [September 30, 2009, 11:22am UTC](https://www.ruby-forum.com/t/page-redirect/176423/2 "2009-09-30T11:22:26Z")

</div>

Hi,  
The solution is simply save requested url in session and after user  
logged  
in send it back to  
the session url.

If you are using restful authentication, you may get the solution,  
[GitHub - technoweenie/restful-authentication: inactive project](http://github.com/technoweenie/restful-authentication).

# Redirect to the URI stored by the most recent store\_location call

or

# to the passed default. Set an appropriately modified

# after\_filter :store\_location, :only =\> [:index, :new, :show, :edit]

# for any controller you want to be bounce-backable.

def redirect\_back\_or\_default(default)  
redirect\_to(session[:return\_to] || default)  
session[:return\_to] = nil  
end

On Wed, Sep 30, 2009 at 2:43 PM, Sharanya S.  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)wrote:

> How to do?
> 
> ## Thankx in advance
> 
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).

## –

Thanks and Regards  
Saurabh P.  
+91-9922071155  
skype: sorab\_pune  
yahoo & gtalk: saurabh.purnaye  
msn: removed\_email\_address@domain.invalid
