gpt4 book ai didi

html - 如何按特定顺序放置学生 block ?

转载 作者:行者123 更新时间:2023-11-28 17:42:33 24 4
gpt4 key购买 nike

如何将学生 block 放在特定顺序?

改为:如果学生 = 3

Student student student  [css block with student_path]

或者 如果学生 = 5

student student student student
student ["stud_path"] ["stud_path"] [stud_path]

我需要:如果学生 = 3

学生学生学生

如果学生 = 5

student student student student
student

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"><pre><%= image_tag(student.try(:picture), height:120, width:90 )%> <%= link_to student.try(:display_name), student_path(student.try(:id))%></pre></td>
<% end %>

你需要测试是否student是否为零:

<% 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 %>

通过在 <td></td> 中进行标签,您仍将保留单元格为空的表格格式。

该测试还可以让您删除 try()方法,因为您知道它不是零。

关于html - 如何按特定顺序放置学生 block ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23844106/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com