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!! -- Posted via http://www.ruby-forum.com/.
> > 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 -- Andrew Stone -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060726/4235b1ab/attachment.html
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 On 7/25/06, Andrew Stone <stonelists@gmail.com> wrote:> > 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 > > -- > Andrew Stone > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails > > >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060726/637f32b3/attachment.html