0

I've created a Resource where I want to group each response by an attribute from an belong_to association.

I've accomplished that with the following code:

fixtures_controller.rb

 def index
    @q = Fixture.ransack(params[:q])
    scope = @q.result(distinct: true)
    @fixture_leagues = scope.filter_by_date_range.group_by {|fixture| fixture.league.name}
  end

fixtures/index.erb

<%= turbo_frame_tag "table" do %>
<p class="loading">Loading...</p>
<div class="-mx-4 overflow-hidden sm:-mx-6 md:mx-0">
    <ul compact="container mx-auto gap-4 list-none">
    <%# render @fixtures %>
    <% @fixture_leagues.each do |league, fixtures| %>
      <h2 class="text-base"><%= league %></h2>  
      <% fixtures.each do |fixture| %>
        <%= render partial:  "fixture", locals: {fixture: fixture} %>
      <% end %>
    <% end %>
    </ul>
    <% end %>
</div>

My issue is that the response can sometimes be really large so I want to have som pagination on the response. But do not know how to accomplish that with a grouped response?

I use Pagy Gem for pagination for my other resources.

And I want the response to be

League 1 Fixture 1 Fixture 2 Fixture 3

League 2 Fixture 4 Fixture 5

League 3 Fixture 6 Fixture 7 Fixture 8 Fixture 9 Fixture 10

(trigger pagination) to see more items.

tommers
  • 51
  • 7

0 Answers0