time time - 4 months ago 20
Ruby Question

Kaminari & Rails pagination - undefined method `current_page'

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

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>


Try with:

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

And then:

<%= paginate @posts %>