我有一个rails应用程序。现在我想获取用户ID以将其存储到数据库中。但是系统显示错误,说id值是nill。
如何将用户ID存储在整数或字符串变量中?
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 => "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