ruby on rails - Adding values together from loop -
i have each loop:
<% user.group(:team).count.each |team, count| %> <%= "the '#{team}' has '#{count} user'" %> <% end %> the output this:
the 'vikings' has '1 user' 'redsocks' has '3 user' 'giants' has '1 user' 'milan' has '2 user' 'iks' has '1 user' 'clampers' has '1 user' i want count added together, , team added together. want output like:
the app has " 9 " users supporting "6 " different teams can advise me on how that?
this way it, recommend move count logic somewhere else view(s)
<% teams_count = 0 %> <% users_count = 0 %> <% team_users_details = [] %> <% user.group(:team).count.each |team, count| %> <% team_users_details << "the '#{team}' has '#{count} user'" %> <% teams_count += 1 %> <% users_count += count %> <% end %> <%= "the app has '#{users_count}' users supporting '#{teams_count}' different teams" %> <%= team_users_details.join(' ') %>
Comments
Post a Comment