问题
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