Kaminari: undefined method `total_pages' for an array

Using Rails and Gemon Kaminari, I get the following error when rendering my view:

undefined method `` total_pages '' for #Array: 0x007faa486583e0

controller:

def index
    @user = current_shop.users.new
    @users = current_shop.active_users   ### This returns an array
    Kaminari.paginate_array(@users).page(params[:page]).per(10)
 end

View:

     <tbody>
       <%= paginate @users %>

        <% @users.each do |user| %>
          <%= render 'user_table_row', :user=> user %>
       <% end %>

     </tbody>

What am I doing wrong?

+4
source share
2 answers

I think you need to assign

@users = Kaminari.paginate_array(@users).page(params[:page]).per(10)

in your controller.

+7
source
 @users = current_shop.active_users.page(params[:page]).per(10)

Do it on ActiveRecord::Collection

-1
source

Source: https://habr.com/ru/post/1610005/


All Articles