Guest User

Untitled

a guest
Mar 11th, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.10 KB | None | 0 0
  1. comment controller - excerpt
  2. --------
  3. # GET /comments/new
  4. # GET /comments/new.xml
  5. def new
  6. @comment = @post.comments.build
  7. @comment.user = @current_user
  8. respond_to do |format|
  9. format.html # new.html.erb
  10. format.xml { render :xml => @comment }
  11. end
  12. end
  13.  
  14.  
  15. show.html.erb
  16. ----
  17. <% unless @post.comments.empty? %>
  18. <% @post.comments.each do |comment| %>
  19. <p><%= h comment.body %><br /><small>Posted on <%= h comment.created_at %> by <%= comment.user.login %></small>
  20. </p>
  21. <% end %>
  22. <% end %>
  23. -----
  24.  
  25. error message i get when this code is in place,
  26. ----
  27.  
  28. NoMethodError in Posts#show
  29.  
  30. Showing posts/show.html.erb where line #12 raised:
  31.  
  32. You have a nil object when you didn't expect it!
  33. The error occurred while evaluating nil.login
  34. Extracted source (around line #12):
  35.  
  36. 9: <!-- #1 -->
  37. 10: <% unless @post.comments.empty? %>
  38. 11: <% @post.comments.each do |comment| %>
  39. 12: <p><%= h comment.body %><br /><small>Posted on <%= h comment.created_at %> by <%= comment.user.login %></small>
  40. 13: </p>
  41. 14: <% end %>
  42. 15: <% end %>
Add Comment
Please, Sign In to add comment