【发布时间】:2017-03-28 11:40:21
【问题描述】:
我的视图中有一个<table>,但它显示的是另一个模型的用户名 -Profile。我正在为表格的每一行调用 Profile。这样做有两个问题:通过调用它来暴露我的模型以及每次调用 Profile 这是低效的。
有没有办法先用一个 SQL 查询访问控制器中的所有用户名,然后相应地只显示表中的每个值,或者有更好的方法来显示没有表的值?
<table class="table table-bordered table-striped">
<thead>
<tr>
<th> Applicant Name </th>
<th> Email </th>
<th> Documents </th>
</tr>
</thead>
<tbody>
<% employee.eager_load(:application).each do |e_application| %>
<tr>
<td><%= Profile.find_by_user_id(e_application.user_id).full_name %></td>
<td><%= mail_to(e_application.applicant.email) %></td>
<td><%= link_to e_application.doc.file.basename, e_application.doc_url if !eapplication.doc.file.nil? %></td>
</tr>
<% end %>
</tbody>
</table>
非常感谢。我是 Rails 新手,没有找到任何示例。
【问题讨论】:
标签: ruby-on-rails forms html-table views