Topic: Session variable changing value
I'm using this method to log users in:
def verify_login
@user = User.find_by_nick(params[:user][:nick])
if @user and @user.password == params[:user][:password]
session[:uid] = @user.id
flash[:notice] = "Hello, #{@user.first_name}. Welcome to RaceBucket."
redirect_to :controller => "user", :action => "mybucket"
else
flash[:notice] = "Invalid login; please try again."
redirect_to :controller => "user", :action => "login"
end
end
This works fine. When I log in I'm redirected to the right page on which I'm displaying the session variable and it's correct. That is, it's storing the proper ID of the user.
I also have this in my application.rb to lookup the user's details on every page load if one exists:
before_filter :identify
def identify
if session[:uid]
@currentuser = User.find(session[:uid])
end
end
Here's the weird part. When I log in, the session variable is set correctly (11 in my testing). As soon as I hit refresh or navigate to another page the session variable gets set to '1'.
I'm not doing this explicitly anywhere that I can see.
Any ideas?