title: Updating partial view with AJAX
body: <p>I have page with many images, each of which has an associated text box used to submit tags on that image. Each image and text box is rendered through a partial view. Currently I am able to update tags and everything works correctly through a full page refresh. I would like to be able to do all this through AJAX, but I'm having some trouble with it.</p>
  
  <p>Here is the form code in the partial view:</p>
  
  <pre><code>&lt;%= image_tag image.src %&gt;
  &lt;%= form_tag :controller =&gt; "images", :action =&gt; :update_tags, :remote =&gt; true, :image =&gt; image.id do %&gt;
    &lt;td&gt;&lt;%= label_tag "Tags:" %&gt;&lt;/td&gt;
    &lt;td&gt;&lt;%= text_field_tag :tags, image.tags %&gt;&lt;/td&gt;
    &lt;td&gt;&lt;%= submit_tag "Submit" %&gt;&lt;/td&gt;
  &lt;% end %&gt;
  </code></pre>
  
  <p>And the main form that calls the partial:</p>
  
  <pre><code>&lt;% @images.each do |image| %&gt;
    &lt;div id="image_#{image.id}"&gt;
      &lt;%= render :partial =&gt; "image_tag", :locals =&gt; { :image =&gt; image } %&gt;
    &lt;/div&gt;
  &lt;% end %&gt;
  </code></pre>
  
  <p>In the :update_tags method in the controller I add the image's tags to the DB and then want to reload that image's partial view.</p>
  
  <p>Here is the controller's redirect code:</p>
  
  <pre><code>respond_to do |format|
    format.js
    format.html { redirect_to :back, :remote =&gt; true }
  end
  </code></pre>
  
  <p>And the update_tags.js.erb:</p>
  
  <pre><code>$("#image_#{image.id}").html( "&lt;%= escape_javascript(render :partial =&gt; 'image_tag', :locals =&gt; {:image =&gt; image} ) %&gt;" );
  </code></pre>
  
  <p>It currently is working functionally, but no AJAX magic happening. I'm still learning Rails and jQuery, so any help would be greatly appreciated. I think I've included all relevant code, but let me know if there's anything else I should provide. Thanks!</p>