When performing a rendering operation on a collection, there are several approarches. A popular one to really modularize and DRY out your code is to use partials. Here is how that is done:
The View
<h3 class="head2">Active Investments</h3> <% unless @session[:user].active_investments.empty? %> <center> <table class="formbox" width="440" cellpadding="5px" cellspacing="0" align="center" style="background-color:#fff"> <tr style="font-weight:bold;boder-bottom:solid 1px:000;"> <td>Investment Amount</td> <td>Origination Date</td> <td>Due Date</td> <td>Check #</td> <td>Status</td> </tr> <%= render :partial => "history_item", :collection => @session[:user].active_investments %> </table> </center> <% else -%> <p>We were unable to find any active online investments.</p> <% end -%>
The Collections Partial
<!-- This bit does highlihting of the rows --> <tr onmouseover="this.className='row_highlight'" onmouseout="this.className='row'"> <%= datatable_investment_agreement_cell(history_item, number_to_currency(history_item.amount))%> <%= datatable_investment_agreement_cell(history_item, dateformat(history_item.start))%> <%= datatable_investment_agreement_cell(history_item, dateformat(history_item.end))%> <%= datatable_investment_agreement_cell(history_item, history_item.check_number)%> <%= datatable_investment_agreement_cell(history_item, history_item.status)%> </tr> <% if history_item.has_renewals? -%> <% history_item.renewals.each do |r| -%> <tr> <td colspan="5" style="text-align:right;font-size:.8em;color:#666;padding-right:30px;"><%= number_to_currency(r.new_investment.amount) %> renewal submitted on <%= fancydateformat(r.created_at) %></td> </tr> <% end -%> <% end -%>