3

Rails 3.2.8 im using kaminari to do pagination, but i keep getting error: undefined method `current_page' for #

in posts_controller.rb

def index
  @posts = Post.order(:created_at).page(params[:page])
end

in views/posts/index.html.erb

<%= paginate @posts %>

what could be the problem?

Nitrino
  • 51
  • 1
  • 3

1 Answers1

0

try to change the code to

@posts = Post.order(:created_at)

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

Or

@posts = Post.order(:created_at).page(params[:page]).per(10)
Kaminari.paginate_array(@posts).page(params[:page]).per(10)

And you can write any number in place of 10 => .per(10) Let the view code remain same.

will_paginate default comes with pagination for ActiveRecord::Relation but for an Array we need to use this particular method.

Nishutosh Sharma
  • 1,926
  • 2
  • 24
  • 39