im making a dynamic table in ruby on rails in which im displaying devices in a table and corresponding to each device i want to show its status which is ibtained dynamically by an ajax function (periodically_call_remote) which updates a div.
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..

how to make div id's as unique (since it need to identify a unique div for each row)

my code goes 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>

kindly help!!
thanx in advance!

I have no idea how to use ruby on rails, but to make a div unique, use some id from the db and place in the html code something like:

<div id='<%==h c.name%>' >test</div>
var uid = (  function(){    var id=0;     return function(){      return id++ ;    };  } )();

var newId = uid();

to get new id use above code

> how to make div id's as unique (since it need to identify a unique div for each row)

One way would be to create a separate counter (e.g. i) which would be incremented for each "for each" block and create an ID dynamically by appending the common name with this counter value. Something like: <div id="<%= puts 'someDiv' + i %>"> (an approximation since I don't know ruby)

This article has been dead for over six months. Start a new discussion instead.