我从rails开始,我不能用rails语法写这个。我可以使用这样的变量吗?如何将2个变量与true,false格式进行比较?
<% n = 0 %>
<% @clas.each do |f| %>
<% if f.clas_id != n %>
<div>
<h2> <%= f.clas_id%></h2>
</div>
<% else %>
<% if f.clas_id = n %>
<div class = "title">
<h3><%= f.name%></h3>
<table>
<tr>
<th>PA</th>
<th>Disim.</th>
</tr>
<tr>
<td><%= f.prec_id %></td>
<td><%= f.dis_id %></td>
</tr>
</table>
</div>
<% else %>
<% n = f.clas_id %><%= n %>
<% end %>
<% end %>
<% end %>
答案 0 :(得分:1)
尝试这样的事情:
<% @clas.each do |f| %>
<% if f.clas_id != n %>
<div>
<h2><%= f.clas_id %></h2>
</div>
<% elsif f.clas_id == n %>
<div class = "title">
<h3><%= f.name %></h3>
<table>
<tr>
<th>PA</th>
<th>Disim.</th>
</tr>
<tr>
<td><%= f.prec_id %></td>
<td><%= f.dis_id %></td>
</tr>
</table>
</div>
<% else %>
<% n = f.clase_id %><%= n %>
<% end %>
<% end %>
我不确定您尝试使用<% n = 0 %>
如果您在Ruby中编写的语句如下,则不要写其他内容:
<% elsif %>