If the goal is to count the number of debts
for each policy
, why not perform the count from Policy
rather than Debt
?
Your controller would change to something like:
class PolicyManagement < ApplicationController
def generate_print_cupons
@search = Policy.all
end
end
Then your view could be as trivial as:
<% @search.each do |policy| %>
<%= policy.debts.size %>
<% end %>