Units have many rooms. Rooms belong to units. When I show the detail
of a unit, I want to show a list of rooms belonging to the unit as well.
In the UnitController:
Room Info<% unless @room.nil? %>
<% for room in @rooms %>
- <%= @room.name %> <% end %>
Yet I still get this exception:
NoMethodError in Units#show
You have a nil object when you didn’t expect it!
You might have expected an instance of Array.
The error occured while evaluating nil.each
- Why do I have a nil array?
- Even if I have a nil array, why doesn’t <% unless @room.nil? %> stop