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?
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
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
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
Frederick Cheung
2008-Mar-11 11:15 UTC
Re: You have a nil object when you didn''t expect it!
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> 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? > -- > Posted via http://www.ruby-forum.com/. > > >--~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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)? On Mar 11, 7:06 am, Alan Red <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> 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? > -- > Posted viahttp://www.ruby-forum.com/.--~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---