Topic: ActionView::TemplateError (undefined method `each' for nil:NilClass)

Hi,
I am very new to Ruby on rails and I am trying to setup a web page that lists all the entries from a mysql database view.
I am getting the error below:


ctionView::TemplateError (undefined method `each' for nil:NilClass) on line #12 of app/views/yosemite_comparisons/_yosemite_comparisons_table.html.erb:
9:     <th> </th>
10:   </tr>
11:
12: <% @yosemite_comparisons.each do |yosemite_comparison| %>
13:   <tr>
14:     <td><%=h yosemite_comparison.command_name %></td>
15:     <td><%=h yosemite_comparison.current_load_test %></td>

    app/views/yosemite_comparisons/_yosemite_comparisons_table.html.erb:12
    app/views/yosemite_comparisons/index.html.erb:4
    app/controllers/yosemite_comparisons_controller.rb:7:in `index'

Rendering /home/administrator/Projects/reporting/public/500.html (500 Internal Server Error)


After reading various posts, I understand that the collection object referenced in my code is NULL. But I don't understand why since I do have data into the database view associated.

Re: ActionView::TemplateError (undefined method `each' for nil:NilClass)

It is fine. I finally found my error. In the controller file for my object, I wrongly defined the collection element as yosemite_comparisons = YosemiteComparison.all instead of @yosemite_comparisons = YosemiteComparison.all

Re: ActionView::TemplateError (undefined method `each' for nil:NilClass)

I was the same problem, but my problem resulted fault the #encoding: utf-8 in my model