Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4548514
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T16:13:52+00:00 2026-05-21T16:13:52+00:00

I know this is a popular topic, but I’ve been searching quite a bit

  • 0

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…

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).

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…

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.

Thanks!

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.

views/requests/index.html.erb

    <table class="center">
<div id="requests">
 <tr>
    <th><%= sortable "Patient_Name", "Patient Name" %></th>
    <th><%= sortable "Room_Number", "Room Number" %></th>
    <th><%= sortable "Request" %></th>
    <th><%= sortable "Urgency" %></th>
    <th><%= sortable "count", "Request Count" %></th>
    <th><%= sortable "created_at", "Created At" %></th>
    <th></th>
  </tr>
<%= render @requests %>
</div>
</table>

Request Partial: views/requests/_request.html.erb

 <div class="request" data-time="<%= request.created_at.to_i %>">
    <tr>
        <td><%= request.Patient_Name %></td>
        <td><%= request.Room_Number %></td>
        <td><%= request.Request %></td>
        <td><%= request.Urgency %></td>
        <td><%= request.count %></td>
        <td><%= request.created_at.getlocal.strftime("%r on %D") %></td>
        <td><%= link_to 'Remove', request, :confirm => 'Are you sure?', :method => :delete %></td>
    </tr>
</div>

views/requests/index.js.erb

$('#requests').append("<%=raw escape_javascript(render(@requests))%>");
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T16:13:53+00:00Added an answer on May 21, 2026 at 4:13 pm

    How is this?

    http://www.datatables.net/

    another whole set are here:

    http://plugins.jquery.com/plugin-tags/ajax-table

    Sometimes it’s better to use what’s there than to build new.

    But to answer your question, it depends on whether you are manipulating the DOM yourself or letting Prototype, jQuery, MooTools, or whatever do the heavy lifting. The idea is to set a timer in your Javascript and when the timer fires, ask the server for updates. The server — your Rails app — will package up whatever has changed and send it back.

    Step 1: Decide on a framework. I use jQuery but most will do.

    Step 2: Decide on a data format. I use JSON, but XML will do.

    Step 3: Set up the timer loop. It involves using settimer() and resetting it after each observation.

    Step 4: In the handler that executes when the timer fires, package up a “last seen” timestamp and make the Ajax request. How you do it varies from framework to framework — or if you are coding right to the DOM, from browser to browser.

    Step 5: Set up a “success” handler so that when your server returns zero or more rows of data, you can insert these TR-TD-/TD-/TR rows in your table.

    Step 6: Update any internal junk like number or row counters or whatever else your Javascript is tracking.

    Note: You may find there are plugins other people have written that will work great and save you the trouble, but you should have a basic understanding of how this is done.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know this question is overly popular, but I find nothing that addresses rewriting
i know, this is a realy popular error. But my problem is that my
I know this won't be a popular question, because a lot of web designers
I know this might be a no-brainer, but please read on. I also know
I know this isn't strictly a programming question but y'all must have experienced this.
I know this is a broad question, but I've inherited several poor performers and
I know this is not programming directly, but it's regarding a development workstation I'm
I know this rather goes against the idea of enums, but is it possible
I know this would be easy with position:fixed, but unfortanately I'm stuck with supporting
I know this exception is pretty popular for SL and WCF developers since I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.