Forum: Ruby on Rails session[:user_id] problem

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
47045582e4791894288d274673bd8f12?d=identicon&s=25 WDZ (Guest)
on 2007-02-08 05:47
(Received via mailing list)

Please help! I ran into a problem that session[:user_id] seems lost.
The session[:user_id] is set during user's login. Other pages have
"before_filter :login_required". The method "login_required" is
defined in ApplicationController to check if session[:user_id] exists.
However, after user logs in successfully (I can see the printed
user_id), and when bringing other pages which call login_required, the
session[:user_id] becomes empty.

I am using rails 1.2.2 and gem version is also 1.2.2.
active_record_store is used for session storage.

Can anyone shed some light on this problem?

Thanks a lot!

5d846c71cd788ba8475a20b045553018?d=identicon&s=25 Bryan Tec (Guest)
on 2007-02-08 06:00
(Received via mailing list)
Are you sure the value is empty and that it's just not a display issue
the other pages?
And is the session still in your db?

If those are good can you post some code so we can get a better idea
going on?

Bryan - Freelance jobs of every type
You're worth something at
47045582e4791894288d274673bd8f12?d=identicon&s=25 WDZ (Guest)
on 2007-02-08 06:13
(Received via mailing list)
Thanks Bryan for your help. Yes, I am sure the value is empty, not
display issue. The session is still in db (sessions table). Here is
part of code:

class IndexController < ApplicationController

  def process_student_login
    if user = User.sauthenticate(params[:user])

        session[:uid] ="session uid = #{session[:uid]}")     # it prints
out uid successfully

class ApplicationController < ActionController::Base
   before_filter :set_user

 def set_user"in set_user: session uid = #{session[:uid]}")
# it prints out nil
    @user = User.find(session[:uid]) if @user.nil? && session[:uid]

  def login_required"in login_required: session uid =
#{session[:uid]}")    # it prints out nil

    return true if @user
    return false

class Myaccount::IndexController < ApplicationController
  before_filter :login_required     #  always fails and returns false


This topic is locked and can not be replied to.