title: Rails - updating div w/ Ajax and :remote => true
body: <p>I've followed this <a href="http://railscasts.com/episodes/205-unobtrusive-javascript" rel="nofollow">Railscast</a> on submitting a form via Ajax and updating a div without reloading the page, but I'm having trouble with one portion of it.</p>
  
  <p>Ryan has <code>$("#products").html("&lt;%= escape_javascript(render(@products)) %&gt;");</code> in an <code>index.js.erb</code> file to update the <code>#products</code> div when the form is submitted. I'm struggling to understand whether an instance variable like <code>@products</code> is relevant for my situation, or if I can simply substitute it for a URL.</p>
  
  <p>I'm trying to do the same thing as Ryan in this screencast, but instead of display search results I just want to display the updated value.</p>
  
  <p><strong>In show.html.erb I have:</strong></p>
  
  <pre><code>&lt;% @project.project_todos.order("created_at DESC").where(:status =&gt; false).each do |todo|%&gt;
  
  &lt;%= form_for todo, :remote =&gt; true, :"data-replace" =&gt; "#dueon" do |f| %&gt;
     &lt;%= f.text_field :due %&gt;
     &lt;%= f.submit :class =&gt; "primary", :value =&gt; "Add" %&gt;
  &lt;% end %&gt;
  
  &lt;div id="dueon"&gt;
     &lt;%= render "duedate", :todo =&gt; todo %&gt;
  &lt;/div&gt;
  
  &lt;% end %&gt;
  </code></pre>
  
  <p>The partial <code>_duedate.html.erb</code> has one line in it: <code>&lt;%= todo.due %&gt;</code></p>
  
  <p>So in my index.js.erb I currently have this: <code>$("#dueon").html("&lt;%= escape_javascript(render("_duedate")) %&gt;");</code> but it's clearly not working. Do I have to use a variable here in place of the <code>_duedate</code>? And if so, how would I set this up in the controller? I mean what does the variable have represent?</p>
  
  <p>Also, for what it's worth, the partial is rendering correctly and displaying the <code>todo.due</code> value...it's just not updating when I submit the form.</p>
  
  <p><strong>ProjectsController:</strong></p>
  
  <pre><code>def show
      @project = Project.find(params[:id])
  
      # Display the form to create a new todo
      @project_todo = ProjectTodo.new
  
      respond_to do |format|
        format.html # show.html.erb
        format.json { render :json =&gt; @project }
      end
    end
  </code></pre>