I have a <table> in a view but it's showing username from another model -Profile. I'm calling Profile for each row of table. There are two problems with this: exposing my model in view by calling it & each time calling Profile which is inefficient.
Is there a way to access all usernames in controller first with one SQL query and then display only each value in table correspondingly or a better approach to show values without table?
<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>
Many thanks. I'm new to rails and not found any example.