title: Ruby and Nil Object
body: <p>I am developing a webapp (well trying to) in Ruby on Rails. </p>
  
  <p>I have a partial render in my index.html.erb </p>
  
  <pre><code>&lt;%= render :partial =&gt; "houses/index", :locals =&gt; @houses %&gt;
  </code></pre>
  
  <p>index.html.erb is loaded when the user hits the root of my domain. This partial cause this error:</p>
  
  <pre><code>You have a nil object when you didn't expect it!
  You might have expected an instance of Array.
  The error occurred while evaluating nil.each
  </code></pre>
  
  <p>Extracted Source around line 8</p>
  
  <pre><code>5:     &lt;th&gt;Washrooms&lt;/th&gt;
  6:   &lt;/tr&gt;
  7: 
  8: &lt;% @houses.each do |house| %&gt;
  9:   &lt;tr&gt;
  10:     &lt;td&gt;&lt;%=h house.short_desc %&gt;&lt;/td&gt;
  11:     &lt;td&gt;&lt;%=h house.bedrooms %&gt;&lt;/td&gt;
  </code></pre>
  
  <p>Trace of template inclusion: app/views/home/index.html.erb</p>
  
  <p>All I would like to is display 5 houses on my Homepage (index.html.erb) </p>
  
  <p>What am I missing to get this to work?</p>
  
  <p>Many thanks</p>
  
  <p>EDIT: </p>
  
  <p><a href="http://pastebin.ca/1666849" rel="nofollow noreferrer" title="houses_controller.rb">Houses_controller</a></p>
  
  <p>NoMethodError in Home#index</p>
  
  <p>Showing app/views/houses/_index.html.erb where line #10 raised:</p>
  
  <p>You have a nil object when you didn't expect it!
  You might have expected an instance of Array.
  The error occurred while evaluating nil.each</p>
  
  <p>Extracted source (around line #10):</p>
  
  <p>7:     Washrooms
  8:   
  9: 
  10: &lt;% @houses.each do |house| %>
  11:   
  12:     &lt;%=h house.short_desc %>
  13:     &lt;%=h house.bedrooms %></p>
  
  <p>Trace of template inclusion: app/views/home/index.html.erb</p>