Kaminari: undefined method `total_pages' for Array

一笑奈何 提交于 2019-12-10 15:26:23

问题


Using Rails & Kaminari gem, I am getting the below error when I render 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?


回答1:


I think you have to assign

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

in your controller.




回答2:


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

Do it on the ActiveRecord::Collection



来源:https://stackoverflow.com/questions/32911379/kaminari-undefined-method-total-pages-for-array

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