in application controller @upcomingevents = Event.all in application layout <% @upcomingevents.each do |upcomingevent| %> <%= upcomingevent.name %> <% end %> there are events.. but i get an error of ActionView::TemplateError (undefined method `each'' for nil:NilClass) on line #77 of app/views/layouts/application.html.erb: 74: <%= content_tag :p, msg, :class => key, :id => key -%> 75: <% end -%> 76: 77: <% @upcomingevents.each do |upcomingevent| %> 78: <%= upcomingevent %> 79: <% end %> 80: <div id="content" class="content">
It would guess that Event.all returned nil. Did you mean to say Event.find(:all) ? On Thu, Aug 20, 2009 at 1:51 PM, spokra <spokra-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > in application controller > > @upcomingevents = Event.all > > in application layout > > <% @upcomingevents.each do |upcomingevent| %> > <%= upcomingevent.name %> > <% end %> > > > there are events.. but i get an error of > > > ActionView::TemplateError (undefined method `each'' for nil:NilClass) > on line #77 of app/views/layouts/application.html.erb: > 74: <%= content_tag :p, msg, :class => key, :id => key -%> > 75: <% end -%> > 76: > 77: <% @upcomingevents.each do |upcomingevent| %> > 78: <%= upcomingevent %> > 79: <% end %> > 80: <div id="content" class="content"> > > > >--~--~---------~--~----~------------~-------~--~----~ 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;ve tried both ways of selecting the data.. and the log shows select * from events.. and doing the find in the console works fine. On Aug 20, 10:57 am, James Englert <englert.ja...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> It would guess that Event.all returned nil. Did you mean to say > Event.find(:all) ? > > On Thu, Aug 20, 2009 at 1:51 PM, spokra <spo...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > in application controller > > > @upcomingevents = Event.all > > > in application layout > > > <% @upcomingevents.each do |upcomingevent| %> > > <%= upcomingevent.name %> > > <% end %> > > > there are events.. but i get an error of > > > ActionView::TemplateError (undefined method `each'' for nil:NilClass) > > on line #77 of app/views/layouts/application.html.erb: > > 74: <%= content_tag :p, msg, :class => key, :id => key -%> > > 75: <% end -%> > > 76: > > 77: <% @upcomingevents.each do |upcomingevent| %> > > 78: <%= upcomingevent %> > > 79: <% end %> > > 80: <div id="content" class="content">
Drrr make a function.. and call it with a before filter.. On Aug 20, 11:04 am, spokra <spo...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I;ve tried both ways of selecting the data.. and the log shows select > * from events.. and doing the find in the console works fine. > > On Aug 20, 10:57 am, James Englert <englert.ja...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > It would guess that Event.all returned nil. Did you mean to say > > Event.find(:all) ? > > > On Thu, Aug 20, 2009 at 1:51 PM, spokra <spo...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > in application controller > > > > @upcomingevents = Event.all > > > > in application layout > > > > <% @upcomingevents.each do |upcomingevent| %> > > > <%= upcomingevent.name %> > > > <% end %> > > > > there are events.. but i get an error of > > > > ActionView::TemplateError (undefined method `each'' for nil:NilClass) > > > on line #77 of app/views/layouts/application.html.erb: > > > 74: <%= content_tag :p, msg, :class => key, :id => key -%> > > > 75: <% end -%> > > > 76: > > > 77: <% @upcomingevents.each do |upcomingevent| %> > > > 78: <%= upcomingevent %> > > > 79: <% end %> > > > 80: <div id="content" class="content">
James Englert wrote:> It would guess that Event.all returned nil. Did you mean to say > Event.find(:all) ?In recent versions of Rails, those two are equivalent. (Of course, we don''t know what version the OP is using...) Best, -- Marnen Laibow-Koser http://www.marnen.org marnen-sbuyVjPbboAdnm+yROfE0A@public.gmane.org -- Posted via http://www.ruby-forum.com/.
2009/8/20 spokra <spokra-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>:> > in application controller > > @upcomingevents = Event.all > > in application layout > > <% @upcomingevents.each do |upcomingevent| %> > <%= upcomingevent.name %> > <% end %> > > > there are events.. but i get an error of > > > ActionView::TemplateError (undefined method `each'' for nil:NilClass) > on line #77 of app/views/layouts/application.html.erb: > 74: <%= content_tag :p, msg, :class => key, :id => key -%> > 75: <% end -%> > 76: > 77: <% @upcomingevents.each do |upcomingevent| %> > 78: <%= upcomingevent %> > 79: <% end %> > 80: <div id="content" class="content">In this sort of situation where one cannot see the cause of the problem by inspection I use ruby-debug to break into the controller and the view to check the value of variables. This usually gives useful clues. Colin
Well since Event.all should have returned an array and not thrown an error, my guess is there is a problem with your model/database. Go into the terminal and open up a session using script/console, at the prompt enter Event.all and see what it returns... On Aug 20, 1:51 pm, spokra <spo...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> in application controller > > @upcomingevents = Event.all > > in application layout > > <% @upcomingevents.each do |upcomingevent| %> > <%= upcomingevent.name %> > <% end %> > > there are events.. but i get an error of > > ActionView::TemplateError (undefined method `each'' for nil:NilClass) > on line #77 of app/views/layouts/application.html.erb: > 74: <%= content_tag :p, msg, :class => key, :id => key -%> > 75: <% end -%> > 76: > 77: <% @upcomingevents.each do |upcomingevent| %> > 78: <%= upcomingevent %> > 79: <% end %> > 80: <div id="content" class="content">