I am trying to paginate the companies by categories, with the idea that I have a similar view structure:
----------------------------
Categoria: Panaderia
----------------------------
Empresa: Panaderia X
Empresa: Panaderia Y
Empresa: Panaderia Z
Pagina 1,2,3
----------------------------
Categoria: Ferreteria
----------------------------
Empresa: Ferreteria X
Empresa: Ferreteria Y
Empresa: Ferreteria Z
Pagina 1,2,3
----------------------------
Categoria: Hoteles
----------------------------
Empresa: Hoteles X
Empresa: Hoteles Y
Empresa: Hoteles Z
Pagina 1,2,3
This I can achieve without any problem ordering them by group_by in the following way:
enterprises_controller.rb
@enterprises = Enterprise.all.group_by { |e| e.enterprise_tag }
index.html.erb
<% @enterprises.each do |enterprise_tag, enterprises| %>
<%= enterprise_tag %>
<% enterprises.each do |enterprise| %>
<%= enterprise.name %>
<% end %>
<% end %>
<%= will_paginate @enterprises, :container => false %>
The problem comes when I try to add the pager like this:
@enterprises = Enterprise.all.paginate(:page => params[:page], :per_page => 6).group_by { |e| e.enterprise_tag }
I get the following error:
undefined method 'total_pages' for #<Hash:0x007f7450797d10>
Extracted source (around line #73):
73 <%= will_paginate @enterprises, :container => false %>
I have tried several ways but I can not find the result, could someone give me a suggestion?