Sessions

hi!

im implementing a login system for a messageboard. tooked from a book.
pretty simple. everythings works great, but in the example the idea is,
when i want to create a new message, the author name shall be tooked
from the session[:user]

def create
params[:message][:date] = Time.now
params[:message][:author_id] = @session[:user].id #here!!

@message = Message.new(params[:message])
if @message.save
  flash[:notice] = 'Message was successfully created.'
  redirect_to :action => 'list'
else
  render :action => 'new'
end

end

but i recive this error:
“Called id for nil, which would mistakenly be 4 – if you really wanted
the id of nil, use object_id”

i dont know why, im following the example step by step. what can i do?

ty!!

but i recive this error:
“Called id for nil, which would mistakenly be 4 – if you really wanted
the id of nil, use object_id”

This means session[:user] hasn’t been set yet. I’m not sure what
example
you are referring to, but in your login method you need to add the user
to
the session.

new_user = User.new()

session[:user] = new_user

btw, I think the convention is to use session not @session. The same
goes
for request, response, flash and some others that escape me right now.

good luck,
andy

depending what book or tut you followed, session[:user] might be the
user
id, not the user object. if that doesn’t work, then what andy said…

ed

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs