title: Rails 3.0 / JQuery - Swapping partials on ajax call
body: <p>I have two partials _choose.html.erb and _details.html.erb.</p>
  <p>I render choose like so:</p>
  <pre><code>&lt;div id=&quot;choose&quot; class=&quot;box&quot; style=&quot;padding:10px;&quot; &gt;
          &lt;%= render :partial =&gt; &quot;choose&quot; %&gt; 
  &lt;/div&gt;
  </code></pre>
  <p>In the controller I call the choose method.</p>
  <pre><code>def choose  
      respond_to do |format|
    format.js
  end
  end 
  </code></pre>
  <p>And in choose.js.erb I call the following:</p>
  <pre><code>$(&quot;#choose&quot;).replaceWith(&lt;%= escape_javascript(render(:partial =&gt; &quot;details&quot;))%&gt;);
  </code></pre>
  <p>But nothing happens.  The details partial is in the correct place and if I render it in the page, like so   &lt;%= render :partial =&gt; &quot;details&quot; %&gt;, up it pops no problem.  But I am unable to swap it using the above ajax method.</p>
  <p>If I do:</p>
  <pre><code>$(&quot;#choose&quot;).replaceWith(&quot;a yaddy yaddy&quot;); 
  </code></pre>
  <p>&quot;a yaddy yaddy&quot; is rendered in the choose div.</p>
  <p>Am I missing something here?</p>
  <p>I have been reading around, including SO, but to no avail.</p>
  <h3>Update</h3>
  <p>The response is either a <code>200</code> or a <code>304</code>. And using firebug, I can see that the response contains the partial contents but this is not rendered in the browser, which is strange, but I'd imagine I have committed some sneaky grievance I'm unaware of....</p>
  <h3>Update</h3>
  <p>in choose.js.erb:</p>
  <p>If I call <code>&quot;$(&quot;#choose&quot;).html(&quot;&lt;%= escape_javascript(render(:partial =&gt; &quot;choose&quot;, :object =&gt; @pages))%&gt;&quot;)&quot;</code> the choose partial is updated with the pages instance variable.</p>
  <p>Thanks, y'all.</p>