# How to redirect back to the page after user Login?

**URL:** <https://www.ruby-forum.com/t/how-to-redirect-back-to-the-page-after-user-login/111674>\
**Category:** Rails\
**Created:** [August 9, 2007, 6:37pm UTC](https://www.ruby-forum.com/t/how-to-redirect-back-to-the-page-after-user-login/111674 "2007-08-09T18:37:31Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mister\_Yu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/22d042/32.png) [@Mister\_Yu](https://www.ruby-forum.com/u/Mister_Yu)\
**Post date:** [August 9, 2007, 6:37pm UTC](https://www.ruby-forum.com/t/how-to-redirect-back-to-the-page-after-user-login/111674/1 "2007-08-09T18:37:31Z")

</div>

Hello all,

I am using acts\_as\_authenticated as my login system.

it does a good job redirecting back to where the user were after  
login, when using the controller action fliter.

however if i use a link in my page to link to the login page, it  
doesn’t redirect back to where the user were after login.

i have a look at the code of AAA, it uses

1. redirect\_back\_or\_default(:controller =\> ‘/account’, :action =\>  
‘index’)
2. 
3. #code for redirect\_back\_or\_default
4. 

```
def redirect_back_or_default(default)

```

5. 

```
  session[:return_to] ?

```

redirect\_to\_url(session[:return\_to]) : redirect\_to(default)  
6. session[:return\_to] = nil  
7. end  
to redirect back to the origin page.

how and where to set the session[:return] in my app to make it  
redirect back to the origin page after login?

Thanks all.
