I have a standard table layout that I would like to use on my index view for 4 different resources. I have created an index_table partial that uses locals to supply the:
- Table title
- Table headers
- Tables objects (such as @users)
- Table cells
<%= render 'shared/index_table',
scope_title: 'All Debts',
table_headers: ['ID', 'Debtor', 'Amount', 'Status', 'Stage', ''],
table_objects: @debts,
table_cells: ['id', 'debtor.name', 'amount', 'status', 'stage'] %>
All but the table cells are working and naturally the problem I am running into is the cell is being displayed as Object.id, rather than the actual object id.
<table class="table table-striped table-bordered table-hover" id="sample_3">
<thead>
<tr>
<% table_headers.each do |table_header| %>
<th> <%= table_header %> </th>
<% end %>
</tr>
</thead>
<tbody>
<% table_objects.each do |object| %>
<tr>
<% table_cells.each do |cell| %>
<td> <%= object %>.<%= cell %> </td>
<% end %>
<td>
<a href="javascript:;" class="btn btn-outline btn-sm blue">
<i class="fa fa-share"></i> View </a>
<a href="javascript:;" class="btn btn-outline btn-sm green-jungle">
<i class="fa fa-edit"></i> Edit </a>
<a href="javascript:;" class="btn btn-outline btn-sm red-mint">
<i class="fa fa-trash"></i> Delete </a>
</td>
</tr>
<% end %>
</tbody>
</table>
Any input would be greatly appreciated.
Also is there a more elegant way of doing this, or is this something that is even suggested?
Thanks for your help!