How to know about user id in sessions in rails
<p>I have a rails app. Now I want to fetch the users id to store it into the database. But system is showing error saying that id value is nill.</p>

<p>How can I store the user id in a integer or string variable?</p>

<pre><code> def create     
    user = User.authenticate(params[:email], params[:password])
    @data=Information.all
    @num=Information.count()
    @tym=Time.now.getutc
    if user
      session[:user_id] = user.id
      @val=session[:user_id]               # is it possible to store user id in variable @val
      #redirect_to root_url, :notice =&gt; "Logged in!"

      #this part is for showing the content of the information table


      respond_to do |format|
        format.html
        format.xml { render xml: @data }
      end
    else
     flash.now.alert = "Invalid email or password"
     render "new"
    end
 end
</code></pre>