보기에는 <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>
감사합니다. 나는 레일을 처음 사용하고 어떤 예도 발견하지 못했습니다.
감사합니다. Sedad. user 테이블에는 full_name이없고 profile 테이블에는 full_name 만 있습니다. 각 응용 프로그램의 사용자 이름을 얻으려면 e_application.user가 도움이되지 않습니다. 프로필 배열에있는 모든 사용자 이름을 수집 한 다음 매핑 할 수 있습니까? – Means