diff --git a/app/controllers/groups_controller.rb b/app/controllers/groups_controller.rb index 2dbcd8a..0cd4055 100644 --- a/app/controllers/groups_controller.rb +++ b/app/controllers/groups_controller.rb @@ -26,9 +26,10 @@ class GroupsController < ApplicationController def index @groups = Group.sorted.all - respond_to do |format| - format.html + format.html { + @user_count_by_group_id = user_count_by_group_id + } format.api end end @@ -138,4 +139,12 @@ class GroupsController < ApplicationController rescue ActiveRecord::RecordNotFound render_404 end + + def user_count_by_group_id + h = User.joins(:groups).group('group_id').count + h.keys.each do |key| + h[key.to_i] = h.delete(key) + end + h + end end diff --git a/app/views/groups/index.html.erb b/app/views/groups/index.html.erb index d48afe9..22c89ef 100644 --- a/app/views/groups/index.html.erb +++ b/app/views/groups/index.html.erb @@ -3,7 +3,6 @@ <%= title l(:label_group_plural) %> - <% if @groups.any? %>
<%= link_to h(group), edit_group_path(group) %> | -<%= group.users.size %> | +<%= @user_count_by_group_id[group.id] || 0 %> | <%= delete_link group %> |