time time - 1 year ago 119
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>

Answer Source

Try with:

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

And then:

<%= paginate @posts %>
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download