HELP -- I'm missing something

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:

It would guess that Event.all returned nil. Did you mean to say
Event.find(:all) ?

2009/8/20 spokra [email protected]:

78: <%= upcomingevent %>
79: <% end %>
80:

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

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.

Drrr make a function… and call it with a before filter…

James E. 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
[email protected]

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…