How to pass collections to Rails partials that contain a block. (Or, how to get around Rails magic).
I have a feeling I'm think about this from the wrong angle. Can anyone point me in teh right direction?
Say I have an index with two repeated blocks, like so:
<div class="content">
<table>
<thead>
<tr>
<th>COL1</th>
<th>COL2</th>
<th>COL3</th>
</tr>
</thead>
<tbody>
<% @collectionA.each do |a| %>
<tr>
<td><%= a.col1 %></td>
<td><%= a.col2 %></td>
<td><%= a.col3 %></td>
</tr>
<% end %>
<tr><%= will_paginate @collectionA %></tr>
</tbody>
</table>
<br />
<table>
<thead>
<tr>
<th>COL1</th>
<th>COL2</th>
<th>COL3</th>
</tr>
</thead>
<tbody>
<% @collectionB.each do |b| %>
<tr>
<td><%= b.col1 %></td>
<td><%= b.col2 %></td>
<td><%= b.col3 %></td>
</tr>
<% end %>
<tr><%= will_paginate @collectionA %></tr>
</tbody>
</table>
</div>
My first round of DRYing up might look something like this.
...
<tbody>
<%= render :partial => 'collections', :collection => @collectionA %>
</tbody>
<%= will_paginate @collectionA %>
...
<tbody>
<%= render :partial => 'collections', :collection => @collectionb %>
</tbody>
<%= will_paginate @collectionB %>
...
But what if I need to move will_paginate
into the partial as well, so that I can ajaxify it.
If I only had one block, I would do
<tbody>
<%= render :partial => 'collection' %>
</tbody>
and in the partial
<% @collection.each do |col| %>
STUFF
<% end %>
<%= will_paginate @collection %>
But if I have two blocks, how can I pass @collection-A and @collection-B into the partial?
Or am I looking at this the wrong way? Thanks for any pointers.