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 :

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

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


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


  <% end %>
<%= will_paginate @devices %>

kindly help!!
thanx in advance!

10 Years
Discussion Span
Last Post by ~s.o.s~

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 topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.