Forum: Ruby on Rails I want my login and logout actions to not change the page

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
73c04e9ef9ca435c5b19a2e765ae6d20?d=identicon&s=25 Max Williams (max-williams)
on 2007-07-23 18:26
I implemented a user login/logout system from this 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 " %> <strong> <%= user.login %> </strong>
<span>    </span>
<%= link_to 'Log out', :controller => "user", :action => "logout" %>
<span>    </span>
<%= link_to 'Change password',  :controller => "user", :action =>
"change_password" %> <br/>

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!
This topic is locked and can not be replied to.