# Problem with session

**URL:** <https://discuss.rubyonrails.org/t/problem-with-session/22773>\
**Category:** rubyonrails-talk\
**Created:** [January 7, 2008, 1:20pm UTC](https://discuss.rubyonrails.org/t/problem-with-session/22773 "2008-01-07T13:20:55Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![ajit1](https://avatars.discourse-cdn.com/v4/letter/a/aeb1de/32.png) [@ajit1](https://discuss.rubyonrails.org/u/ajit1)\
**Post date:** [January 7, 2008, 1:20pm UTC](https://discuss.rubyonrails.org/t/problem-with-session/22773/1 "2008-01-07T13:20:55Z")

</div>

Hi, I have problem when i tried to logging logging successfull, but when tried to find out the current cuser details by session it always says nil

code for loging:-

@user = User.new(params[:user]) &nbsp;&nbsp;&nbsp;&nbsp;#session[:user\_id] = nil

&nbsp;&nbsp;&nbsp;&nbsp;case request.method &nbsp;&nbsp;&nbsp;&nbsp;when :post

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;respond\_to do |format| &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if @current\_user = User.authenticate(@user.email, params[:user] [:hashed\_password]) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;session[:user\_id] = @current\_user.id &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;flash[:notice] = "user login successfully !!!" &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;format.html { redirect\_to(users\_path) } &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;else &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;flash[:notice] = " better try next time !!!" &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;format.html { render :action =\> "index" } &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end

i want to fetch user details from user table by from user controller Couldn't find User with ID=2

but the current user id is not 2, it always take id 2 code:- @user=User.find(session[:user\_id])

Thank's ajit
