# Return to Request Page after login

**URL:** <https://www.ruby-forum.com/t/return-to-request-page-after-login/142006>\
**Category:** Rails\
**Created:** [July 2, 2008, 4:10pm UTC](https://www.ruby-forum.com/t/return-to-request-page-after-login/142006 "2008-07-02T16:10:46Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![mitch\_newbie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ea5d25/32.png) [@mitch\_newbie](https://www.ruby-forum.com/u/mitch_newbie)\
**Post date:** [July 2, 2008, 4:10pm UTC](https://www.ruby-forum.com/t/return-to-request-page-after-login/142006/1 "2008-07-02T16:10:46Z")

</div>

I have a login form on the left column of a site I am building. The  
user can visit any page and the form is always present on the left. The  
middle column of the site is used for the display of site information  
etc.

My question.

Once the user logs in how to I direct them back to the page they were  
viewing at the time of registration since it could be any page in the  
site?

Thank you for your time in advance.

---

<div class="post-metadata">

**Author:** ![mitch\_newbie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ea5d25/32.png) [@mitch\_newbie](https://www.ruby-forum.com/u/mitch_newbie)\
**Post date:** [July 2, 2008, 4:15pm UTC](https://www.ruby-forum.com/t/return-to-request-page-after-login/142006/2 "2008-07-02T16:15:37Z")

</div>

On Jul 2, 2008, at 10:10 AM, Mitchell G. wrote:

> My question.
> 
> Once the user logs in how to I direct them back to the page they were  
> viewing at the time of registration since it could be any page in the  
> site?

redirect\_to :back

check the API for more detail,

> **[ActionController::Base](https://api.rubyonrails.org/classes/ActionController/Base.html)**
>
> Action Controllers are the core of a web request in Rails. They are made up of one or more actions that are executed on request and then either it renders a template or redirects to another action.

Best.  
Mike

---

<div class="post-metadata">

**Author:** ![mitch\_newbie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ea5d25/32.png) [@mitch\_newbie](https://www.ruby-forum.com/u/mitch_newbie)\
**Post date:** [July 2, 2008, 4:16pm UTC](https://www.ruby-forum.com/t/return-to-request-page-after-login/142006/3 "2008-07-02T16:16:12Z")

</div>

Store the last action in a session variable.  
store using  
session[:action] = :action\_name\_to\_Return\_to  
before login

On the return page,  
you can do something like redirect\_to :action = session[:action] ||  
= :default\_action

arun

On Jul 2, 10:10 am, Mitchell G. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![mitch\_newbie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ea5d25/32.png) [@mitch\_newbie](https://www.ruby-forum.com/u/mitch_newbie)\
**Post date:** [July 2, 2008, 4:23pm UTC](https://www.ruby-forum.com/t/return-to-request-page-after-login/142006/4 "2008-07-02T16:23:54Z")

</div>

Arun Gokule wrote:

> Store the last action in a session variable.  
> store using  
> session[:action] = :action\_name\_to\_Return\_to  
> before login
> 
> On the return page,  
> you can do something like redirect\_to :action = session[:action] ||  
> = :default\_action
> 
> arun
> 
> On Jul 2, 10:10ï¿½am, Mitchell G. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

Great I will try this and get back to you

---

<div class="post-metadata">

**Author:** ![mitch\_newbie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ea5d25/32.png) [@mitch\_newbie](https://www.ruby-forum.com/u/mitch_newbie)\
**Post date:** [July 2, 2008, 4:24pm UTC](https://www.ruby-forum.com/t/return-to-request-page-after-login/142006/5 "2008-07-02T16:24:20Z")

</div>

Michael B. wrote:

> On Jul 2, 2008, at 10:10 AM, Mitchell G. wrote:
> 
> > My question.
> > 
> > Once the user logs in how to I direct them back to the page they were  
> > viewing at the time of registration since it could be any page in the  
> > site?
> 
> redirect\_to :back
> 
> check the API for more detail,  
> [ActionController::Base](http://api.rubyonrails.org/classes/ActionController/Base.html)
> 
> Best.  
> Mike

Thanks Mike,  
I will look into this.
