Rails 3 - html.erb中的表格 [英] Rails 3 - tables in html.erb

查看:131
本文介绍了Rails 3 - html.erb中的表格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在视图中查看来自不同数据库表的数据,如下图所示:

I'd like to view data from different database-tables in a view with tables like this picture shows:

我熟悉HTML标签< table> < td> < tr> ,但我在列中遇到多个查询时遇到问题。

I'm familiar with HTML tags <table>, <td> and <tr>, but I'm having trouble with multiple queries in a column.

<table>
  <tr>
    <th>Skills &nbsp; &nbsp; &nbsp;</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>

此代码如下所示:

如您所见,技能,预期资格和现有资格重复。

As you can see, the skills, expected-qualifications, and current-qualifications repeat.

我的问题:如何在表中订购代码,以便它看起来像我想要的那样?

My question: How should the codes be ordered in the table so it will look the way I want it to?

推荐答案

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

这篇关于Rails 3 - html.erb中的表格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆