Kaminari.paginate_array ArgumentError (wrong number of arguments (2 for 1)
Asked Answered
P

1

2

I am using a rails application with the kaminari gem and I have a common array that I am trying to page using the paginate_array method but I am getting a ArgumentError (wrong number of arguments (2 for 1) exception. Here is the code:

def index    

    page = params[:page] || 1
    items = ClientReports.search(params[:search], sort_column, sort_direction)
    @clients =  Kaminari.paginate_array(items, total_count: items.count).page(page)

    respond_with(@clients)

  end

The line: Kaminari.paginate_array(items, total_count: items.count).page(page) is the one throwing the error. Why is this a problem? From what I can see the docs show this should be ok.

Piecework answered 4/11, 2015 at 13:55 Comment(2)
Try @clients = Kaminari.paginate_array([items], total_count: items.count).page(page)Dive
yep, that's it. Submit this as an answer please. Strange that I need to specify the total_count though.Piecework
D
4

ArgumentError (wrong number of arguments (2 for 1)

From the docs,

You can specify the total_count value through options Hash.

Example

@paginatable_array = Kaminari.paginate_array([], total_count: 145).page(params[:page]).per(10)

So in your case it should be

@clients = Kaminari.paginate_array([items], total_count: items.count).page(page)
Dive answered 4/11, 2015 at 14:15 Comment(1)
2 things, 1) the docs only tell you can specify it the array has a count different than items.count which is not the case here. 2) since items is already an array, [items] would cause problems. Thanks though.Piecework

© 2022 - 2024 — McMap. All rights reserved.