You have a nil object when you didn't expect it!

Im trying to get information from a database and display it on a view, I
am using this in the controller:

def comment
@comments = Rating.find(:all)

respond_to do |format|
  format.html # show.html.erb
  format.xml  { render :xml => @comments }
end

end

and this to display the information

<% for comment in @comments %>
<%=h comment.item_name %>
<%=h comment.comment %>
<%=h comment.seller_rating %>
<%=h comment.advert_rating %>
<% end %>

Yet I get an error saying i have a nil object, can anyone help me
please?

On 11 Mar 2008, at 11:06, Alan Red wrote:

Im trying to get information from a database and display it on a
view, I
am using this in the controller:

The error should include a stack trace which should tell you on which
line it’s happening (and this which object is (unexpectedly) nil.

Fred

I agree with Fred, but my wild guess is going to be that you’ve got a
view that is geared up for Comments but a controller that’s retrieving
a Rating. Do you need to do something more like
Comment.find(params[:id], :include=>:ratings)?