title: Rails 3 AJAX solution for updating tables?
body: <p>I know this is a popular topic, but I've been searching quite a bit trying to find the answer and strangely haven't found anything that has been able to help...</p>
  
  <p>I've got a basic Rails 3 application displaying database entries in a table. A separate application posts new entries into the database, and I'd like the Rails app to poll and refresh to display the new content. Right now, I have a terrible piece of javascript simply reloading the whole page and its proving to be my roadblock. I have a search bar and check bars to remove multiple items, but these are both reset upon a page refresh (again, I know this is awful and horrendously broken). </p>
  
  <p>From what I have read, I gather that I should use AJAX to poll the database and simply render  database entries that are newer than the newest entry displayed. How to precisely execute this is another story...</p>
  
  <p>Most of the tutorials I have found have been out of date, and I've been unable to get the legacy code running. I am new to both AJAX and Rails, and I would love if anyone has any guidance, advice, tutorials, or personal criticism (:P) that may point me in the right direction.</p>
  
  <p>Thanks!</p>
  
  <p>EDIT: I've got new entries being pulled into the page, but they aren't rendering correctly at all. For some reason, they aren't being added as entries into my table. Here's my code, hopefully you guys might be able to pick something out I missed:
  * Note -> requests are actually the name of my database entries. Requests is the model.</p>
  
  <h2>views/requests/index.html.erb</h2>
  
  <pre><code>    &lt;table class="center"&gt;
  &lt;div id="requests"&gt;
   &lt;tr&gt;
      &lt;th&gt;&lt;%= sortable "Patient_Name", "Patient Name" %&gt;&lt;/th&gt;
      &lt;th&gt;&lt;%= sortable "Room_Number", "Room Number" %&gt;&lt;/th&gt;
      &lt;th&gt;&lt;%= sortable "Request" %&gt;&lt;/th&gt;
      &lt;th&gt;&lt;%= sortable "Urgency" %&gt;&lt;/th&gt;
      &lt;th&gt;&lt;%= sortable "count", "Request Count" %&gt;&lt;/th&gt;
      &lt;th&gt;&lt;%= sortable "created_at", "Created At" %&gt;&lt;/th&gt;
      &lt;th&gt;&lt;/th&gt;
    &lt;/tr&gt;
  &lt;%= render @requests %&gt;
  &lt;/div&gt;
  &lt;/table&gt;
  </code></pre>
  
  <h2>Request Partial: views/requests/_request.html.erb</h2>
  
  <pre><code> &lt;div class="request" data-time="&lt;%= request.created_at.to_i %&gt;"&gt;
      &lt;tr&gt;
          &lt;td&gt;&lt;%= request.Patient_Name %&gt;&lt;/td&gt;
          &lt;td&gt;&lt;%= request.Room_Number %&gt;&lt;/td&gt;
          &lt;td&gt;&lt;%= request.Request %&gt;&lt;/td&gt;
          &lt;td&gt;&lt;%= request.Urgency %&gt;&lt;/td&gt;
          &lt;td&gt;&lt;%= request.count %&gt;&lt;/td&gt;
          &lt;td&gt;&lt;%= request.created_at.getlocal.strftime("%r on %D") %&gt;&lt;/td&gt;
          &lt;td&gt;&lt;%= link_to 'Remove', request, :confirm =&gt; 'Are you sure?', :method =&gt; :delete %&gt;&lt;/td&gt;
      &lt;/tr&gt;
  &lt;/div&gt;
  </code></pre>
  
  <h2>views/requests/index.js.erb</h2>
  
  <pre><code>$('#requests').append("&lt;%=raw escape_javascript(render(@requests))%&gt;");
  </code></pre>