我有一个观点,有一个部分:
显示:
<!-- This must happen at regular intervals -->
<td><%= link_to edit_simulation_path(@simulation), @simulation, method: :put, id: @simulation.id, data: { remote: true }, :class => "btn btn-default btn-xs" %></td>
<%= render 'simulation' %>
<%= link_to 'Back', simulations_path %>
_simulation:
<div id="sim_div">
<h1><%= @simulation.identifier %></h1>
<h4>Dimensions: <%= @simulation.x_size %>x<%= @simulation.y_size %></h4>
<h4>Verdict: <%= @simulation.verdict %></h4>
<ul>
<li> This should display the seating arrangement of the current simulation </li>
<li> This should dispaly the verdict of the current state of the simulation </li>
<li> It should automatically and asynchronously update itself to the next state at a regular interval. </li>
</ul>
<table class="table table-bordered">
<thead>
<tr>
</tr>
</thead>
<tbody>
<% @simulation.state.each do |row| %>
<tr>
<% row.each do |current| %>
<td class="text-center"><%= current %></td>
<% end%>
</tr>
<% end %>
</tbody>
</table>
<br>
</div>
现在按钮将异步调用更新,更新模拟状态并刷新部分而不刷新整个页面。
按钮<!-- This must happen at regular intervals -->
我想每隔x秒运行一次,而不是一个可点击的按钮。而只是一个定期执行的动作。
我在网上找到的所有内容都是使用cron,但肯定他们必须采用更简单的方式(仅当此视图打开时)。