Issues with update div using ajax

Hi! I have been trying to use periodically_Call_remote in a table showing various devices , to update a row specific to a device.

my view looks like:

<html> <body> <p><strong>All Devices</strong><hr /></p>

<table width="300" border="1">   <thead>     <tr>       <th width="130" scope="col">Device Name</th>     <th width="100" scope="col">Ping Result</th>

    </tr>   </thead>   <tbody>

   <% @devices.each do |c|%> <tr>        <td>           <%=h c.name%> </td> <%= javascript_include_tag :defaults %> <%= periodically_call_remote(:update => "log_entry", :url => {:action => 'get_ping_entry', :id => c.id}, :frequency =>3) %> <td> <div id="log_entry">

</div> </td>

</tr>    <% end %>   </tbody> </table> <%= will_paginate @devices %> </body> </html>

and my controller action is :

def get_ping_entry @dev=Dev.find(params[:id]) @status= Ipaddr.find(:first,:conditions=>["dev_id =?",@dev.id]).status render_text "status "+@status.to_s    end

its working fine but its updating only the first row i.e. its showing result of periodically call remote for every device in the first row only..not in the corresponding row for each device..

can you please help me with this?? thanking in advance

Your div ids need to be unique.

Fred

yes i understood wats the problem… the id’s need to be unique… can you help me with that?? i t ried some methods but no help !! once again thanx alot for your prompt reply!

yes i understood wats the problem.. the id's need to be unique.. can
you help me with that?? i t ried some methods but no help !! once again thanx alot for your prompt reply!

just generate a unique string "log_entry_#{c.id}"

Fred

i tried with this … this isnt working , updating nothing on the page

<%= javascript_include_tag :defaults %> <%= periodically_call_remote(:update =>“log_entry_#{c.id}”, :url => {:action => ‘get_ping_entry’, :id => c.id}, :frequency =>3) %>

i tried with this .. this isnt working , updating nothing on the page

<%= javascript_include_tag :defaults %> <%= periodically_call_remote(:update =>"log_entry_#{c.id}", :url =>
{:action => 'get_ping_entry', :id => c.id}, :frequency =>3) %> <td> <div id="log_entry_<%#{c.id}%>" >

Get your erb right: <%= c.id%> (you could tell this was the problem by
looking at the html output)

Fred

Hey!

Thanx alot! it worked fine :slight_smile:

Thanx boss…!

If you're in Rails 2.x, use the dom_id method to create the id <div id="log_entry_<%= c.id %>"> ~ <div id="<%= dom_id(device, :log_entry) %>">

Or, since you specifically want a div:

<% div_for device do %> ... <% end %>