session problem in ruby on rails

Hai!

I have two controller. the one is first_controller and another one is
second_controller.

first_controller.rb

def login
.
.
if @user && @user.password == params[:user][:password]
  session[:user_id] = @user.id
  redirect_to :controller => "second_controller", :action => "index"
end
end

second_controller.rb

def index
if session[:user_id] != nil
  logger.info" The user id is not null"
else
  logger.info" The user id is null"
end
end

#=======Result
The user id is not null # 1st time
The user id is null # 2nd time
The user id is not null # 3rd time
The user id is not null # 4th time
The user id is null # 5th time
The user id is not null # 6th time
The user id is not null # 7th time
The user id is not null # 8th time
The user id is not null # 9th time
The user id is not null # 10th time
The user id is not null # 11th time
The user id is null # 12th time

Here my session variable id dynamic not a static. But i want static
value.
I hope this is session problem. help me.

Thanks for you.
bdeveloper01

Hai!

I tried

   session[:user_id].freeze

but I got same problem

At-last I got one solution.

def login
.
.
if @user && @user.password == params[:user][:password]
  session[:user_info_id] = session[:user_id] = @user.id
  session[:user_info_id].freeze
  redirect_to :controller => "second_controller", :action => "index"
end
end

second_controller.rb

def index
if session[:user_info_id] != nil
  session[:user_id] = session[:user_info_id]
  logger.info" The user id is not null"
else
  logger.info" The user id is null"
end
end

===========>result

The user id is not null
The user id is not null
The user id is not null
The user id is not null
The user id is not null
The user id is not null
The user id is not null
The user id is not null
The user id is not null
The user id is not null
The user id is not null
The user id is not null

Thanks for ruby-forum
by:
bdeveloper01