Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- comment controller - excerpt
- --------
- # GET /comments/new
- # GET /comments/new.xml
- def new
- @comment = @post.comments.build
- @comment.user = @current_user
- respond_to do |format|
- format.html # new.html.erb
- format.xml { render :xml => @comment }
- end
- end
- show.html.erb
- ----
- <% unless @post.comments.empty? %>
- <% @post.comments.each do |comment| %>
- <p><%= h comment.body %><br /><small>Posted on <%= h comment.created_at %> by <%= comment.user.login %></small>
- </p>
- <% end %>
- <% end %>
- -----
- error message i get when this code is in place,
- ----
- NoMethodError in Posts#show
- Showing posts/show.html.erb where line #12 raised:
- You have a nil object when you didn't expect it!
- The error occurred while evaluating nil.login
- Extracted source (around line #12):
- 9: <!-- #1 -->
- 10: <% unless @post.comments.empty? %>
- 11: <% @post.comments.each do |comment| %>
- 12: <p><%= h comment.body %><br /><small>Posted on <%= h comment.created_at %> by <%= comment.user.login %></small>
- 13: </p>
- 14: <% end %>
- 15: <% end %>
Add Comment
Please, Sign In to add comment