forms - Rails views-table to display value from another model -
i have <table> in view it's showing username model -profile. i'm calling profile each row of table. there 2 problems this: exposing model in view calling & each time calling profile inefficient.
is there way access usernames in controller first 1 sql query , display each value in table correspondingly or better approach 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 |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 rails , not found example.
for start don`t
profile.find_by_user_id(e_application.user_id).full_name if did relations correctly call
e_application.user.full_name in case don`t have user
e_application.try(&:user).try(&:full_name) use don`t error.
single dot notations example no need complicate things.
Comments
Post a Comment