Forum: Ruby on Rails help: session is deleted, but after the view is rendered

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.
C4635cd7f47b7c581e295f57d5864e0d?d=identicon&s=25 Merrick Johnson (merrick)
on 2008-12-21 23:43
Scenario:

user is logged in, they click the logout button, which fires the action
method Sessions#destroy and the view. The problem i'm having is that
even tho the session is deleted, the first go round it still displays
logged in. If you refresh it then says not logged in. I am not sure how
to even begin debugging this. thanks!

Controller:

class SessionsController < ApplicationController
  ...
  def destroy
    session[:user_id] = @current_id = nil
  end
end

Main layout:

...
<% if @current_user %>
  Logged in as: <%= @current_user.login %>
  <em><%= link_to 'Logout', session_path, :method => :delete %></em>
<% else %>
  <em>Not logged in.</em>
  <%= link_to 'Login', new_session_path %>
<% end %>
...
81b61875e41eaa58887543635d556fca?d=identicon&s=25 Frederick Cheung (Guest)
on 2008-12-22 00:08
(Received via mailing list)
On Dec 21, 10:43 pm, Merrick Johnson <rails-mailing-l...@andreas-
s.net> wrote:
> Scenario:
>
> user is logged in, they click the logout button, which fires the action
> method Sessions#destroy and the view. The problem i'm having is that
> even tho the session is deleted, the first go round it still displays
> logged in. If you refresh it then says not logged in. I am not sure how
> to even begin debugging this. thanks!

>
> Controller:
>
> class SessionsController < ApplicationController
>   ...
>   def destroy
>     session[:user_id] = @current_id = nil

Don't you want to nil out @current_user rather than @current_id ?

Fred
C4635cd7f47b7c581e295f57d5864e0d?d=identicon&s=25 Merrick Johnson (merrick)
on 2008-12-22 00:22
> Don't you want to nil out @current_user rather than @current_id ?
>
> Fred

good call fred! thanks pal, worked like a charm.
This topic is locked and can not be replied to.