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.
How can I store the user id in a integer or string variable?
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
Aucun commentaire:
Enregistrer un commentaire