# I want my login and logout actions to not change the page

**URL:** <https://www.ruby-forum.com/t/i-want-my-login-and-logout-actions-to-not-change-the-page/110136>\
**Category:** Rails\
**Created:** [July 23, 2007, 6:26pm UTC](https://www.ruby-forum.com/t/i-want-my-login-and-logout-actions-to-not-change-the-page/110136 "2007-07-23T18:26:43Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![cmaxvv](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/85f322/32.png) [@cmaxvv](https://www.ruby-forum.com/u/cmaxvv)\
**Post date:** [July 23, 2007, 6:26pm UTC](https://www.ruby-forum.com/t/i-want-my-login-and-logout-actions-to-not-change-the-page/110136/1 "2007-07-23T18:26:43Z")

</div>

I implemented a user login/logout system from this tutorial:  
[http://www.aidanf.net/rails\_user\_authentication\_tutorial](http://www.aidanf.net/rails_user_authentication_tutorial)

It has seperate screens for every action: login, change password etc.  
When you logout it redirects you to the login screen.

I changed it so that the options are all at the top of my standard app  
screens (such as ‘list’ and ‘show’). Now when you logout, it tries to  
take you to the login screen, which is now redundant. I hardcoded it to  
return me to the ‘list’ page after logging in or logging out, and that  
works ok in that you can log in and out happily, staying on the list  
screen all the time.

But, the problem is that when the user logs in or out on the ‘show’  
page, i want to stay on the ‘show’ page, and similarly for other pages  
i’ve not got round to doing yet. In other words, the log in and log out  
shouldn’t change pages, it should go stay on the current page.

Does anyone know the best way to implement this? Here’s my current code  
in case that helps.

in the logged\_in partial, shown at the top of my ‘list’ and ‘show’  
pages:

\<% user = session[:user] %\>  
\<%= "You are logged in as " %\> **\<%= user.login %\>**   
  
\<%= link\_to ‘Log out’, :controller =\> “user”, :action =\> “logout” %\>  
  
\<%= link\_to ‘Change password’, :controller =\> “user”, :action =\>  
“change\_password” %\>

logout calls this action, in UserController:

def logout  
session[:user] = nil  
flash[:message] = ‘Logged out’  
#hardcoded to return to the list page  
#(newspipe is the name of my app)  
redirect\_to :controller =\> “newspipe”, :action =\> “list”  
end

How can i make it stay on the page it was at instead of hardcoding a  
page like above?  
thanks in advance for any advice!
