Question

this is my post_controller

def index
@posts = Post.all.page(params[:page]).per(2)


respond_to do |format|
  format.html # index.html.erb
  format.json { render json: @posts }
end
 end

this is /views/posts/index

<%= paginate @posts %>

and i recive:

NoMethodError in PostsController#index

undefined method `page' for #


I saw many themes with the same error and solution:

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

but where should i put this?

Was it helpful?

Solution

You can put it in your controller

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

But you also could do this:

@posts = Post.page(params[:page]).per(2)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top