Update rails variable from database

Hi all.

Im using ROR and am trying to get some data from a database into a web page then periodically update this information say every 5 seconds. Ive got the content working statically and have the div refreshing at intervals, the only problem now is passing that new information from the database into the variable.I guess I have to use AJAX for this. Anyone got any ideas? Thanks

Hi all.

Im using ROR and am trying to get some data from a database into a web page then periodically update this information say every 5 seconds. Ive got the content working statically and have the div refreshing at intervals, the only problem now is passing that new information from the database into the variable.I guess I have to use AJAX for this. Anyone got any ideas?

Rails has a helper (periodically_call_remote) that will generate javascript that calls an action at the specified interval and updates the specified div with whatever is rendered by the action

Fred

Frederick Cheung wrote:

Rails has a helper (periodically_call_remote) that will generate javascript that calls an action at the specified interval and updates the specified div with whatever is rendered by the action

Also note that the Rails helper is a thin wrapper around Prototype's Ajax.PeriodicalUpdater.

http://api.prototypejs.org/ajax/ajax/periodicalupdater/

Frederick Cheung wrote:

Hi all.

Im using ROR and am trying to get some data from a database into a web page then periodically update this information say every 5 seconds. Ive got the content working statically and �have the div refreshing at intervals, the only problem now is passing that new information from the database into the variable.I guess I have to use AJAX for this. Anyone got any ideas?

Rails has a helper (periodically_call_remote) that will generate javascript that calls an action at the specified interval and updates the specified div with whatever is rendered by the action

Fred

Would you be able to take a look at the code below. Ive done what you've suggested and from the Rails console I can see that the data is been queried at a regular interval and the div is refreshing but the new data is not being inserted. FYI the value of @uptime is taken from an SNMP query in the controller.

Thanks

[code] <% content_for :subtitle do %>Log Collector Server Status<%end%> <p></p> <% content_for :error do %> <%=javascript_include_tag 'application'%> <%=javascript_include_tag 'prototype'%>   <% if @collectorstatus == TRUE%>       <div class="success">Network Log Collector Is Online</div>       <div class="info">IP: 192.168.1.204</div>       <div class="info2">Uptime: <%=@uptime%></div>       <script src="http://ajax.googleapis.com/ajax/       libs/jquery/1.3.0/jquery.min.js"></script>       <script>       var auto_refresh = setInterval(       function()       {       $('.info2').fadeOut('fast').fadeIn("fast");       }, 1);       </script>

      <%=periodically_call_remote(:url => 'status', :frequency => '5', :update => '.info2')%>   <%else if @collectorstatus == FALSE%>       <div class="error">Network Log Collector Is Offline!</div>   <%else%> <%end%> <%end%> <%end%> <% content_for :content do %>   <% if @collectorstatus == TRUE%>     <div id="gauges2">      <% visualization "ProcessorGauge", "Gauge", :width =>500, :height =>200, :redFrom => 90, :redTo=> 100, :yellowFrom=>80, :yellowTo=> 90, :minorTicks=> 5, :html => {:class => "gauge"} do |chart| %>             <% chart.string "Name" %>             <% chart.number "Values" %>             <% chart.add_rows([                             ["Processor ",@processorusage],                             ["Mem Used ",@memoryint]                     ]) %>     <% end %>     <% end %>     </div> <%end%>

[/code]