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

断了今生、忘了曾经 提交于 2019-12-11 12:03:43

问题


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.


回答1:


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)


来源:https://stackoverflow.com/questions/33523671/kaminari-paginate-array-argumenterror-wrong-number-of-arguments-2-for-1

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!