title: Show action in partial won't display in index view - rails
body: <p>I have my show action within a partial called properties/_property_details.html.erb that I'm trying to display with ajax within the index action's view. </p>
  
  <p>properties/index.html.erb:</p>
  
  <pre><code>&lt;div id="showdiv"&gt;
      &lt;%= render :partial =&gt; 'property_details' %&gt;
    &lt;/div&gt;
  </code></pre>
  
  <p>properties/_property_details.html.erb:</p>
  
  <pre><code>&lt;div id="response"&gt;
  &lt;h3&gt;
  &lt;%= [@property.Address,@property.City,"FL"].join(", ") %&gt; &lt;%= @property.Zip %&gt;&lt;/h3&gt; 
  etc etc     &lt;/div&gt;
  </code></pre>
  
  <p>However, when I try to load the index page the @property variable of the show action is nil so I get an </p>
  
  <pre><code>undefined method `Address' for nil:NilClass
  </code></pre>
  
  <p>presumably because there is no (params[:id]) for the show action as required in the properties_controller:</p>
  
  <pre><code>def show
  @property = Property.find(params[:id])
  
  respond_to do |format|
    format.js {render :partial =&gt; 'property_details' ,:layout =&gt; false}
    format.html
  end
  
  end
  </code></pre>
  
  <p>But if that's the case then I should be able to hard code a value for @property in the show action just to test this but the following code still gives the same undefined method for nilclass error when I try to load the index page containing the partial:</p>
  
  <pre><code>def show
    @property = Property.find(1)
  
  respond_to do |format|
    format.js {render :partial =&gt; 'property_details' ,:layout =&gt; false}
    format.html
  end
  
  end
  </code></pre>
  
  <p>Why is @property coming back as nil? I opened the rails console and did p = Property.find(1) and got a property returned so for some reason the partial isn't listening to the show action in the controller when it's within my index page.</p>
  
  <p>The partial works fine when it's within the properties/show.html.erb like this:</p>
  
  <pre><code>&lt;div class="twothirds"&gt;
  &lt;%= render :partial =&gt; 'property_details' %&gt;
  &lt;/div&gt;
  &lt;div class="onethird"&gt;
  &lt;%= render :partial =&gt; 'property' %&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>So it's only when I'm trying to put the partial within my index page that it doesn't work. What am I doing wrong?</p>