我想在视图中查看来自不同数据库表的数据,如下图所示:
我熟悉HTML标记< table>,< td>和< tr>,但我在列中遇到多个查询时遇到问题.
<table> <tr> <th>Skills </th> <th>Expected-qualifications</th> <th>Current-qualifications</th> </tr> <% @employee.position.skills.each do |skill| %><% @employee.position.expected_qualifications.each do |expected_qualification| %><% @employee.current_qualifications.each do |current_qualification| %> <tr> <td><%= skill.kategorien %></td> <td><%= expected_qualification.sollqualifikation %></td> <td><%= current_qualification.istqualifikation %></td> </tr> <% end %><% end %><% end %> </table>
此代码如下所示:
如您所见,技能,预期资格和当前资格重复.
我的问题:如何在表格中排序代码,以便它看起来像我想要的那样?
解决方法
试试
zip:
<% @employee.position.skills.zip(@employee.position.expected_qualifications,@employee.current_qualifications).each |skill expected_qualification current_qualification| %> <tr> <td><%= skill.kategorien %></td> <td><%= expected_qualification.sollqualifikation %></td> <td><%= current_qualification.istqualifikation %></td> </tr> <% end %>