Kaminari & Rails pagination - undefined method `current_page'

time picture time · Jun 26, 2012 · Viewed 23.9k times · Source

I searched and searched, but nothing solved my problem. Here's my controller:

def show
    @topic = Topic.find(params[:id])
    @topic.posts = @topic.posts.page(params[:page]).per(2) # 2 for debugging
end

That functions just fine, because the topic view is reduced to two posts. However, when I add this to show.html.erb:

<%= paginate @topic.posts %>

I'm given this error:

undefined method `current_page' for #<ActiveRecord::Relation:0x69041c9b2d58>

Answer

Nicolas Garnil picture Nicolas Garnil · Jun 26, 2012

Try with:

def show
  @topic = Topic.find(params[:id])
  @posts = @topic.posts.page(params[:page]).per(2)
end

And then:

<%= paginate @posts %>