rails session handling on windows problems

I'm doing a simple demo on a windows box, showing how simple it is to do a user login page, using code from the Agile Programming with Rails book.

Unfortunately, it's not acting simple.

This is the view for the login.

<% @page_title = 'Login' %> <%= error_messages_for 'user' %>


<% if session[:user_id] %> <%= start_form_tag :action => 'login' %>   <%= render :partial => 'users/form' %>   <%= submit_tag "Login" %> <%= end_form_tag %> <% else %> <p>You are logged-in.</p> <% end %>

<% if session[:user_id] %> <p>You can logout here.</p>     <%= link_to 'Logout', :action => 'logout' %> <% end %>

Even though both of these sections depend on the :user_id symbol in the session hash, the first one is working and the second is not.

Also, while logout will run when told, for some reason it stays logged-in.

Here are the login and logout actions.

def login         if request.get?             session[:user_id] = nil             @user = User.new         else             @user = User.new(params[:user])             begin                 logged_in_user = @user.try_to_login             rescue                 flash[:notice] = "System error in login attempt!"                 render             end             if logged_in_user                 session[:user_id] = logged_in_user.id                 flash[:notice] = "Logged in as #{logged_in_user.name}!"                 redirect_to(:controller => 'login', :action => 'index')             else                 flash[:notice] = "Invalid user/password combination"             end         end   end

  def logout     session[:user_id] = nil     flash[:notice] = "You are logged-out"     redirect_to(:action => 'index')   end

I'm lost. I'm doing something similar on a linux box and it works fine.

Is this a problem with Rails on Windows?

Thanks, Mike

Keynan Pratt wrote:

#First change the view to be

<%= error_messages_for 'user' %>

<h1><%= @page_title || 'Login' %></h1>

<% if @logged_in? -%>

What provides @logged_in? ? That looks like a method call but you're referencing it like an instance variable, and it's nowhere in my code.

I do see that my logic was bad here, but worse, in my controller, if you visit the login page you are logged-out. This was the core issue.

Thanks, Mike