Bonjour,
je rencontre un gros problème depuis plus d'une semaine. Débutant en programmation ruby,je cherche à afficher toutes les 5s 10 lignes d'une table dans ma base de données dans un tableau. Le problème est que quand j'exacute mon code, il m'affiche les 10 premières lignes et 10s plutard, il n'ya rien. Mon tableau n'est pas mis à jour en insèrant les nouvelles lignes dans ce meme tableau.
Dans mon controlleur, j'ai ceci:
def list_capture
@id_last = Packet.last.id
@packets = Packet.where(:id => (@id_last-50)..(@id_last))
render :layout => false
end
Dans ma vue, j'ai ceci:
<div id="tableau" name="tableau">
<table id="contenu">
<thead>
<tr>
<th scope="col"><strong> Detail</strong></th>
<th scope="col"><strong>Numéro</strong></th>
<th scope="col"><strong>Temps</strong></th>
<th scope="col"><strong>Source</strong></th>
<th scope="col"><strong>Destination</strong></th>
<th scope="col"><strong>Protocole</strong></th>
<th scope="col"><strong>Message</strong></th>
</tr>
</thead>
<tbody id="tb">
<% @packets.each do |packet| %>
<% if packet %>
<tr>
<td><p onmouseover="montre('<%= packet.detail %>');" onmouseout="cache();"><%= link_to image_tag("Icone_loupe.png", :border =>'0')%></p>
</td>
<td><%= packet.number %></td>
<td><%= packet.time %></td>
<td><%= packet.source %></td>
<td><%= packet.destination %></td>
<td><%= packet.protocol %></td>
<td><%= packet.information %></td>
</tr>
<% end %>
<% end %>
</tbody>
</table>
</div>
<% @packets = Packet.where(:id => (@packets.last.id+1)..(@packets.last.id+51)) %>
<%= observe_field "contenu",
:frequency => 5,
:url => {:action => 'list_capture'},
:update =>'capture'
Dans capture.js.rjs:
@packets.each { |pack|
page.insert_html :after, "contenu",render :partial =>'capture'
}
Mais jusque là rien ne marche! Quelqu'un sait-il comment faire avec AJAX? des exemples en Ajax que je vois c'est avec des texfield.
Merci!
Partager