I have three partials that I'd like to consolidate into one. They share the same collection, but each gets passed its own :local variable. Those variables are used for specific Models, so as a result, I have three different calls to the partial and three different partials.
Here's the repetitive code:
<% for email in campaign.emails %>
<h4><%= link_to email.title, email %> <%= email.days %> days</h4>
<% @contacts= campaign.contacts.find(:all, :order => "date_entered ASC" )%> <!--contacts collection-->
<!-- render the information for each contact -->
<%= render :partial => "contact_email",
:collection => @contacts,
:locals => {:email => email} %>
<% end %>
Calls in this Campaign:
<% for call in campaign.calls %>
<h4><%= link_to call.title, call %> <%= call.days %> days</h4>
<% @contacts= campaign.contacts.find(:all, :order => "date_entered ASC" )%> <!--contacts collection-->
<!-- render the information for each contact -->
<%= render :partial => "contact_call",
:collection => @contacts,
:locals => {:call => call} %>
<% end %>
Letters in this Campaign:
<% for letter in campaign.letters %>
<h4><%= link_to letter.title, letter %> <%= letter.days %> days</h4>
<% @contacts= campaign.contacts.find(:all, :order => "date_entered ASC" )%> <!--contacts collection-->
<!-- render the information for each contact -->
<%= render :partial => "contact_letter",
:collection => @contacts,
:locals => {:letter => letter} %>
<% end %>
An example of one of the partials is as follows:
<
div id="contact_email_partial">
<% if from_today(contact_email, email.days) < 0 %>
<% if show_status(contact_email, email) == 'no status'%>
<p> <%= full_name(contact_email) %>
<% unless contact_email.statuses.empty?%>
(<%= contact_email.statuses.find(:last).status%>)
<% end %>
is <%= from_today(contact_email,email.days).abs%> days overdue:
<%= do_event(contact_email, email) %>
<%= link_to_remote "Skip Email Remote",
:url => skip_contact_email_url(contact_email,email),
:update => "update-area-#{contact_email.id}-#{email.id}" %>
<span id='update-area-<%="#{contact_email.id}-#{email.id}"%>'> </span>
<% end %>
<% end %>
</div>
And here is the other partial...similar, eh? Need help making it DRY!
<% if (from_today(contact_call, call.days) < 0) %>
<% if show_status(contact_call, call) == 'no status'%>
<p> <%= full_name(contact_call) %>
<% unless contact_call.statuses.empty?%>
(<%= contact_call.statuses.find(:last).status%>)
<% end %>
is <%= from_today(contact_call,call.days).abs%> days overdue:
<%= do_event(contact_call, call) %>
<%= contact_call.phone %>
</p>
<% end %>
<% end %>