user1658756
user1658756

Reputation: 1024

Issue With Will Paginate and Index Action

In my controller for the index action, I have;

def index
  @documents = current_user.documents.all if current_user
end

Anything I add on the end of current_user I get an error. For example, I tried to add will_paginate which is simply adding .paginate(:per_page => 5, :page => params[:page]) to the end of the index action and adding <%= will_paginate @documents %> to the views.

Once I add the .paginate(:per_page => 5, :page => params[:page]) to the end of the index method, like this;

def index
  @documents = current_user.documents.all if current_user.paginate(:per_page => 5, :page => params[:page])
end

I get a NoMethodError. Anybody know how to fix this?

Upvotes: 0

Views: 77

Answers (2)

Tolik Kukul
Tolik Kukul

Reputation: 2016

Try

def index
  @documents = current_user.documents.paginate(:per_page => 5, :page => params[:page]) if current_user
end

Upvotes: 1

Ahmad Sherif
Ahmad Sherif

Reputation: 6223

You're calling the method on the wrong object, here is the correct one:

@documents = current_user.documents.paginate(:per_page => 5, :page => params[:page]) if current_user

Upvotes: 0

Related Questions