ビューには<table>
がありますが、別のモデルのユーザー名 - Profile
が表示されています。私はテーブルの各行にProfileを呼んでいます。これには2つの問題があります。非効率なProfileを呼び出すたびに&と呼ぶことで、モデルを公開しています。他のモデルからの値を表示するためのビュービュー -
コントローラ内のすべてのユーザー名に1つの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>
多くのありがとう。私はレールが新しく、例は見つからなかった。
ありがとうSedad。 userテーブルにはfull_nameがなく、profileテーブルにはfull_nameしかありません。各アプリケーションのユーザー名を取得するには、e_application.userは役に立ちません。プロファイル配列内のすべてのユーザー名を収集してマップできますか? – Means