Skip to content

Instantly share code, notes, and snippets.

@elvisgiv
Created June 28, 2016 15:08
Show Gist options
  • Save elvisgiv/2ea189885620dda62bb1435e66cc82bb to your computer and use it in GitHub Desktop.
Save elvisgiv/2ea189885620dda62bb1435e66cc82bb to your computer and use it in GitHub Desktop.

#Задача - показать количество продуктов в списке категорий ##Controllers

nodes_controller.rb

def index
    @items = Node.includes(:cluster => [:team]).by_filter(@filter)

    # for count
    node_ids = Node.pluck(:id)
    @containers_count = ClusterContainer.where(:node_id => node_ids).group(:node_id).count
end

##View

nodes/index.html.haml

...
%table.table.table-striped.table-bordered.table-hover
  %tr
    ...
    %th Containers

  - @items.each do |item|
...
      %td
        = link_to admin_cluster_containers_path(:node_id => item.id) do
          containers
          %span
            (#{@containers_count[item.id] || 0})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment