Rails - periodically update certain tags without refreshing the page
===

I am creating a statusboard that will show specific details of several servers and need help with updating the view.

**Background:** 
I have the main setup created where I have the following: 

 - A MySQL database that keeps hold of the server information called servers
 - Using bootstrap to show the content
 - A ruby script to grab each servers information and updating the database (method called update_all_servers in the application.rb file)
 - Cronjob that runs the ruby script every minute

**What I need help with:** 
Basically, I need help with the javascript part of my rails app. I am not too sure exactly how too update individual attributes of each server in the table I have. What I am looking for is that the javascript/ajax code will periodically grab the updated values from the database every 30 seconds and update the view without refreshing the page. 

In my index.html, you can see that I have placed an id="comments" for the server.rhel_version attribute. I was thinking I could use the $(#comments).<some ajax/javscript code> to update it. Either in the application.js file or some other efficient/logical method. 

Below is all my source code. If you guys could guide me on the approach I should take and possibly provide some sample code, I would really appreciate it!

**/views/servers/index.html.erb**

    <%- model_class = Server.new.class -%>
    <div class="page-header">
      <h1><%=t '.title', :default => model_class.model_name.human.pluralize %></h1>
    </div>
    <table class="table table-striped">
      <thead>
        <tr>
     <!--     <th><%= model_class.human_attribute_name(:id) %></th> -->
          <th><%= model_class.human_attribute_name(:hostname) %></th>
          <th><%= model_class.human_attribute_name(:port) %></th>
      <!--    <th><%= model_class.human_attribute_name(:username) %></th>
          <th><%= model_class.human_attribute_name(:password) %></th>
          <th><%= model_class.human_attribute_name(:ssh_username) %></th>
          <th><%= model_class.human_attribute_name(:ssh_password) %></th> 
          <th><%= model_class.human_attribute_name(:source_branch) %></th> -->
          <th><%= model_class.human_attribute_name(:source_revision) %></th>
          <th><%= model_class.human_attribute_name(:release) %></th>
          <th><%= model_class.human_attribute_name(:rhel_version) %></th>
          <th><%= model_class.human_attribute_name(:gpu_type) %></th>
          <th><%= model_class.human_attribute_name(:total_users) %></th>
          <th><%= model_class.human_attribute_name(:current_users) %></th>
          <th><%= model_class.human_attribute_name(:created_at) %></th>
          <th><%=t '.actions', :default => t("helpers.actions") %></th>
        </tr>
      </thead>
      <tbody>
        <% @servers.each do |server| %>
          <tr>
      <!--      <td><%= link_to server.id, server_path(server) %></td> -->
            <td><%= server.hostname %></td>
            <td><%= server.port %></td>
       <!--     <td><%= server.username %></td>
            <td><%= server.password %></td>
            <td><%= server.ssh_username %></td>
            <td><%= server.ssh_password %></td>
            <td><%= server.source_branch %></td> -->
            <td><%= server.source_revision %></td>
            <td><%= server.release %></td>
            <td id="comments"><%= server.rhel_version %></td>
            <td><%= server.gpu_type %></td>
            <td><%= server.total_users %></td>
            <td><%= server.current_users %></td>
            <td><%=l server.created_at %></td>
            <td>
              <%= link_to t('.edit', :default => t("helpers.links.edit")),
                          edit_server_path(server), :class => 'btn btn-mini' %>
              <%= link_to t('.destroy', :default => t("helpers.links.destroy")),
                          server_path(server),
                          :method => :delete,
                          :confirm => t('.confirm', :default => t("helpers.links.confirm", :default => 'Are you sure?')),
                          :class => 'btn btn-mini btn-danger' %>
            </td>
          </tr>
        <% end %>
      </tbody>
    </table>
    
    <%= link_to t('.new', :default => t("helpers.links.new")),
                new_server_path,
                :class => 'btn btn-primary' %>

**/controllers/servers_controller.rb**

    class ServersController < ApplicationController
      # GET /servers
      # GET /servers.json
      def index
        @servers = Server.all
    
        update_all_servers
    
        respond_to do |format|
          format.html # index.html.erb
          format.json { render json: @servers }
        end
      end
    
      # GET /servers/1
      # GET /servers/1.json
      def show
        @server = Server.find(params[:id])
    
        respond_to do |format|
          format.html # show.html.erb
          format.json { render json: @server }
        end
      end
    
      # GET /servers/new
      # GET /servers/new.json
      def new
        @server = Server.new
    
        respond_to do |format|
          format.html # new.html.erb
          format.json { render json: @server }
        end
      end
    
      # GET /servers/1/edit
      def edit
        @server = Server.find(params[:id])
      end
    
      # POST /servers
      # POST /servers.json
      def create
        @server = Server.new(params[:server])
    
        respond_to do |format|
          if @server.save
            format.html { redirect_to @server, notice: 'Server was successfully created.' }
            format.json { render json: @server, status: :created, location: @server }
          else
            format.html { render action: "new" }
            format.json { render json: @server.errors, status: :unprocessable_entity }
          end
        end
      end
    
      # PUT /servers/1
      # PUT /servers/1.json
      def update
        @server = Server.find(params[:id])
    
        respond_to do |format|
          if @server.update_attributes(params[:server])
            format.html { redirect_to @server, notice: 'Server was successfully updated.' }
            format.json { head :no_content }
          else
            format.html { render action: "edit" }
            format.json { render json: @server.errors, status: :unprocessable_entity }
          end
        end
      end
    
      # DELETE /servers/1
      # DELETE /servers/1.json
      def destroy
        @server = Server.find(params[:id])
        @server.destroy
    
        respond_to do |format|
          format.html { redirect_to servers_url }
          format.json { head :no_content }
        end
      end
    end


**/assets/javascripts/application.js**

    // This is a manifest file that'll be compiled into application.js, which will include all the files
    // listed below.
    //
    // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
    // or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
    //
    // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
    // the compiled file.
    //
    // WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD
    // GO AFTER THE REQUIRES BELOW.
    //
    //= require jquery
    //= require jquery_ujs
    //= require twitter/bootstrap
    //= require_tree .

**Screenshot of view:** 
![statusboard view][1]


  [1]: http://i.stack.imgur.com/6KbtP.png