On Thu, Mar 4, 2010 at 5:42 AM, Michael Pavling <[email protected]> wrote: > On 4 March 2010 10:29, Neil Bye <[email protected]> wrote: >> >> You have a nil object when you didn't expect it! >> The error occurred while evaluating nil.login >> >> Extracted source (around line #2): >> >> 1: <p id="story"><%= comment.content %></p> >> 2: <p>Submitted by:<%=comment.user.login %></p> >> > > You're being told that you have a nil object on line 2 when evaluating > the "login" method. So "user" is nil - and I'd guess we'd expect it to > be a User object... > I can't see anywhere in the controller (CommentController I assume) > that assigns a user to a comment, so that's a good place for you to > start. > Make sure somewhere does something along the lines of "comment.user = > current_user"... even hard-code comment.user_id to a known value to > check that when there *is* a user on the comment, the view displays > correctly. Then you can go back and make sure the comment is being > built properly.
It might also be an ideal to add validates_presence_of :user to the comment model and either use save! or check the result of save when creating the comments. -- Rick DeNatale Blog: http://talklikeaduck.denhaven2.com/ Twitter: http://twitter.com/RickDeNatale WWR: http://www.workingwithrails.com/person/9021-rick-denatale LinkedIn: http://www.linkedin.com/in/rickdenatale -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

