You want to do all the calculation on the server in your controller action before rendering the view.
So in addition to gathering the @deals
, you will also set an instance variable for the count.
def index
@deals = Deals.all # or whatever your finder is
@common_listitem_count = ListItem.where(code: @deals.pluck(:code)).count
end
Then just call the count instance variable in the view:
<%= @common_listitem_count %>