Html 如何按一定顺序放置学生块?

Html 如何按一定顺序放置学生块?,html,css,ruby-on-rails,Html,Css,Ruby On Rails,如何在中放置学生块 一定的顺序 改为: 如果学生=3 或 如果学生=5 我需要: 如果学生=3 学生 或 如果学生=5 view.rb <table> <% if @students %> <% @students.in_groups_of(4) do |students| %> <tr> <% students.each do |student| %> <t

如何在中放置学生块 一定的顺序

改为: 如果学生=3

或 如果学生=5

我需要: 如果学生=3

学生

如果学生=5

view.rb

<table>
<% if @students %>
    <% @students.in_groups_of(4) do |students| %>
        <tr>
          <% students.each do |student| %>
              <td id="stud"><pre><%= image_tag(student.try(:picture), height:120, width:90 )%> <%= link_to student.try(:display_name), student_path(student.try(:id))%></pre></td>
          <% end %>
        </tr>
    <% end %>
<% end %>
</table>

而不是:

<% students.each do |student| %>
  <td id="stud">
    <% if student %>
      <pre><%= image_tag(student.picture, height:120, width:90 )%> <%= link_to student.display_name, student_path(student.id)%></pre>
    <% end %>
  </td>
<% end %>
通过在
标记中执行此操作,您仍将保留单元格为空的表的格式

该测试还允许您删除
try()
方法,因为您知道它不是零

student student student student
student
<table>
<% if @students %>
    <% @students.in_groups_of(4) do |students| %>
        <tr>
          <% students.each do |student| %>
              <td id="stud"><pre><%= image_tag(student.try(:picture), height:120, width:90 )%> <%= link_to student.try(:display_name), student_path(student.try(:id))%></pre></td>
          <% end %>
        </tr>
    <% end %>
<% end %>
</table>
<% students.each do |student| %>
  <td id="stud"><pre><%= image_tag(student.try(:picture), height:120, width:90 )%> <%= link_to student.try(:display_name), student_path(student.try(:id))%></pre></td>
<% end %>
<% students.each do |student| %>
  <td id="stud">
    <% if student %>
      <pre><%= image_tag(student.picture, height:120, width:90 )%> <%= link_to student.display_name, student_path(student.id)%></pre>
    <% end %>
  </td>
<% end %>